5

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].
Roman C
  • 49,761
  • 33
  • 66
  • 176
Pigueiras
  • 18,778
  • 10
  • 64
  • 87
  • try `index` – Jaiwo99 Aug 23 '12 at 09:00
  • I believe S2 filter is treating it as an action.I remember i was having same issue where i want the `` as my action and i removed the extension like `.jsp` from the list and created an empty file name `index` – Umesh Awasthi Aug 23 '12 at 09:09
  • I proved with an Action in the `` before I put this here but since I read here that I can't do that directly (http://stackoverflow.com/questions/39399/how-can-i-set-the-welcome-page-to-a-struts-action) I didn't put here. I'm getting a different error, I will put it in the question. – Pigueiras Aug 23 '12 at 09:33
  • @Pigueiras:This is what you all need to do ,1) create an empty file namely `index` in your web-app than you need to define a mapping in your struts file like ``Hope i am clear enough.One more point for putting comment please mark person name else that person will not get any notification about your comment – Umesh Awasthi Aug 23 '12 at 09:45
  • @UmeshAwasthi Sorry, I always forget about it. Put that as an answer and I will mark it, thanks a lot! – Pigueiras Aug 23 '12 at 10:02
  • @Pigueiras: I will, just curious was the suggestion helpful to some extend :)? – Umesh Awasthi Aug 23 '12 at 10:05
  • @UmeshAwasthi No, I don't have enough knowledge for doing extends hehe =P – Pigueiras Aug 23 '12 at 10:22

2 Answers2

8

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.

Umesh Awasthi
  • 23,407
  • 37
  • 132
  • 204
2

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>
MarkOnJava
  • 21
  • 1