Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why welcome-file-list is not working if I remove struts2 .action extension?

I have a problem if I remove the .action extension inside my Struts2 application. I put this in my struts.xml:

<constant
    name="struts.action.extension"
    value="" />

The application works correctly except in the index page. I have in my web.xml this:

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

When I access to http://localhost/myApp/, I get the following error:

There is no Action mapped for namespace [/] and 
action name [index.jsp] associated with context path [/myApp]. 
- [unknown location]

However if I access to http://localhost/myApp/fooAction, I'm not getting any errors and works perfectly.

If I change the extension for a non empty extension (like "html"), I see the index page perfectly if I access to http://localhost/myApp/.

So then, is there something wrong in what I'm doing? Why am I getting this error when I remove extension? Is there any posible way of not getting it?

Edit: If I put an action in the <welcome-page> the error is the following:

There is no Action mapped for namespace [/] and action name [] 
associated with context path [/myApp].
like image 576
Pigueiras Avatar asked Aug 23 '12 08:08

Pigueiras


People also ask

What is action name struts2?

The action tag allows the programmers to execute an action from the view page. They can achieve this by specifying the action name. They can set the "executeResult" parameter to "true" to render the result directly in the view.

How does Struts2 work?

The request is first sent from the browser to the server. Then the server loads the web. xml and if the request pattern matches then it is forwarded to the FilterDispatcher.

What is action mapping in Struts?

An ActionMapping represents the information that the controller, RequestProcessor , knows about the mapping of a particular request to an instance of a particular Action class.


2 Answers

I was having same issue in one of the application where i need to call an Action on page load in place of index.jsp or welcom.jsp in <welcome-page>.I did the following steps

Placed the following entry in my web.xml.

 <welcome-file-list>
            <welcome-file>index</welcome-file>
</welcome-file-list>

I created an empty file with name index in my web-app folder and finally placed the following entry in my struts.xml file

<action name="index" class="welcomeAction">
     <result>/ab.jsp</result>
 </action>

So in this case when i was hitting this URL www.myapp.com/myApp,its calling index action of Struts2 and i was able to do all init work for my welcome page.

like image 162
Umesh Awasthi Avatar answered Nov 14 '22 22:11

Umesh Awasthi


I had same issue, but solved!!!!
If u use

<constant name="struts.action.extension" value=""/> 

in struts.xml
then put welcome file as

<welcome-file>index.jsp</welcome-file> 

in web.xml
and give the action in struts.xml as follows

<package name="default" extends="struts-default">
    <action name="index.jsp">
        <result>WEB-INF/login.jsp</result>
    </action>
</package>
like image 32
MarkOnJava Avatar answered Nov 14 '22 23:11

MarkOnJava