1

I'm learning Struts 2 for a project requirement and I've met some issues.

Following this tutorial at:

http://www.mkyong.com/google-app-engine/google-app-engine-struts-2-example/

And what I've done extra:

  • Added an index.jsp into the war folder
  • Changed web.xml to

    <?xml version="1.0" encoding="utf-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        version="2.5">
        <filter>
            <filter-name>struts2</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>
    
        <filter-mapping>
            <filter-name>struts2</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    
        <listener>
            <listener-class>com.mkyong.listener.Struts2ListenerOnGAE</listener-class>
        </listener>
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>
    

Now, when I rebuild and loads

    http://localhost:8888

Rather then seeing the content I should have in my index.jsp, I'm getting a

    Error 404 There is no Action mapped for namespace [/] and action name [] associated with context path [].

Can someone point me to the right direction? I've seen some other similar questions in SO but their solutions do not work for this specific example of Struts 2 + GAE.

My struts.xml

    <struts>
        <package name="user" namespace="/User" extends="struts-default">
            <action name="Login">
                <result>pages/login.jsp</result>
            </action>
            <action name="Welcome" class="com.mkyong.user.action.WelcomeUserAction">
                <result name="SUCCESS">pages/welcome_user.jsp</result>
            </action>
        </package>
    </struts>

Folder structure

I cant post images so, http://i.imgur.com/KSPmaMr.png

Exact same libraries used for download

http://www[dot]mediafire[dot]com/?utliwvcmo63o8l7

halfer
  • 19,824
  • 17
  • 99
  • 186
Eleazar
  • 21
  • 4
  • I guess ,you have not mapped the action-name in your struts.xml file, please show me your struts.xml file. – arvin_codeHunk Feb 01 '13 at 06:34
  • @arvin_codeHunk Hi, as per the tutorial, there wasnt a need for a struts mapping to index.html no? Sorry new to this. – Eleazar Feb 01 '13 at 06:38
  • I guess you have deleted everything from `web.xml` file, above is the only content in web.xml now as I can't see the mapping to `filterdispatcher` that actually looks for struts.xml file. – Prateek Feb 01 '13 at 06:41
  • ok,is your struts.xml file is in your root directory, i mean where you have placed your struts.xml file? – arvin_codeHunk Feb 01 '13 at 06:42
  • I know ,there is no need of action_mapping for index.jsp but if you have copy-pasted the code ,then you need to mapped all the action which is resides in your view – arvin_codeHunk Feb 01 '13 at 06:45
  • @pKs , I have included the entire file. – Eleazar Feb 01 '13 at 06:49
  • @arvin_codeHunk , however, I can load index.html just fine and I see everything, even the Action classes are working fine with all the linkages. Is there anything else I need to add/change? – Eleazar Feb 01 '13 at 06:50
  • if all is working fine, then what is your problem ,tell me specifically, and where you put your struts.xml file – arvin_codeHunk Feb 01 '13 at 06:53
  • @arvin_codeHunk , struts.xml file is in my root src folder. The problem is I want to change index.html to index.jsp but simply including the index.jsp in the same folder as index.html currently and changing the welcome-file to index.jsp cause that error I've stated. – Eleazar Feb 01 '13 at 06:57
  • @Eleazar Have you resolved the issue , I guess you should first understand how exactly the flow between these files work or how actually the struts2 framework works. – Prateek Feb 01 '13 at 07:07
  • @pKs I have not unfortunately. I come from a struts 1 background and trying to understand struts 2 by examples. – Eleazar Feb 01 '13 at 07:09
  • @Eleazar `<%@ taglib prefix="s" uri="/struts-tags" %>` have you specified the taglib in your `index.jsp` :) – Prateek Feb 01 '13 at 07:13

2 Answers2

1

ok ,i got your problem,

change your struts.xml to this

  <struts>
       <package name="default" extends="struts-default" namespace="/">
            <action name="Login">
                <result>pages/login.jsp</result>
            </action>
            <action name="Welcome" class="com.mkyong.user.action.WelcomeUserAction">
                <result name="SUCCESS">pages/welcome_user.jsp</result>
            </action>
        </package>
    </struts>

I guess this will work, because filterDispatcher search for struts.xml file in root folder if you put your struts.xml file in root directory.

arvin_codeHunk
  • 2,328
  • 8
  • 32
  • 47
  • I have changed it but it does not work. From what i can tell, you changed the package name from user to default? I'm trying to make pointing to index.jsp in the welcome-file work though. struts.xml is in my root /src folder – Eleazar Feb 01 '13 at 07:06
  • ok, your url http://localhost:8888, why this is showing your portname only this should be like this http://localhost:8888/your-project-name – arvin_codeHunk Feb 01 '13 at 07:19
  • Yes I can load http://xxxx.com/index.jsp fine with no problems. But I'm trying to make index.jsp load when I enter http://xxxx.com which in this case is the localhost:8888 I dont want my users to go to http://xxxx.com/projectname I feel it is excessive when they can just go to xxxx.com – Eleazar Feb 01 '13 at 07:34
  • you have just missed the point, if you run your project on localhost using ide then the should be like this localhost:8888/your-project-name – arvin_codeHunk Feb 01 '13 at 07:37
  • Sorry I have missed that. However, the project name is Struts2GoogleAppEngine. And loading, http://localhost:8888/Struts2GoogleAppEngine also gives the same error. – Eleazar Feb 01 '13 at 07:47
  • I have added the folder structure image to the first post. – Eleazar Feb 01 '13 at 08:01
1

@Eleazar I followed the mykong tutorial link that you mentioned in your question. There is no use of index.html as far as I see that tutorial. <welcome-list> file is used when the is no action mentioned on application startup.

On step:8 in that tutorial they has provided the url which is http://localhost:8888/User/Login.action you need to run the test. Its got nothing to do with file in welcome list...

UPDATE:

You are getting that error because you have added struts2 filter as /*, and your action namespace is for /User. There is not action namespace for /. Adding package with name="default" with namespace="/" i.e <package name="default" extends="struts-default" namespace="/"></package> will resolve you issue. It will hit <welcome-file>

DarkHorse
  • 2,740
  • 19
  • 28
  • Yes I understand where you're coming from. However, I would like to include an index.jsp as the 'landing' page for wherever i'm trying to deploy. which in this case, it is localhost:8888 I want localhost:8888, or when i deploy on websites, to have their root point to my index.jsp first. This is what i'm trying to make happen but its not allowing me to. – Eleazar Feb 01 '13 at 07:32
  • ok then do this define another package in struts.xml i.e `` before your package with name user. Dont write any actions in it. Keep index.jsp in web-content folder. And run app. hope you see you index.jsp page – DarkHorse Feb 01 '13 at 07:39
  • Thanks for your response, I have just tried this too and the error still comes up. ): – Eleazar Feb 01 '13 at 07:54
  • Eleazar did you followed the article exactly ? Do you have THE SAME versions of all the libraries of the article ? If you call http://localhost:8888/User/Login.action it is not possible you get errors for "/" namespace anymore, you will be on /User namespace... – Andrea Ligios Feb 01 '13 at 08:57
  • @AndreaLigios Yes Andrea, you are right. But that is not the problem. I can reach Login.action just fine. The problem is i'm trying to reach a index.jsp at the main domain like http://localhost:8888/ when the default is a index.html I used exactly the same versions of those libraries stated in the tutorial. I will attach a zip of all the libraries used in the first post. And yes, I followed all the steps closely. If you try it out, i'm sure you will hit the same error. I'm on eclipse IDE juno. – Eleazar Feb 01 '13 at 10:03
  • Its clearly a problem of namespace... my suggestion should work :( – DarkHorse Feb 01 '13 at 10:16
  • Can you try it out too and see if you get the error? I have attached the files needed. Source code is also on the website. ): – Eleazar Feb 01 '13 at 10:45
  • @Eleazar I have got busy with important work, will try as soon as I get free coz I need to download GAE SDK for that.. need some more time:P – DarkHorse Feb 05 '13 at 07:03