This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes struts2 default extension change issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "struts2 default extension change issue" Watch "struts2 default extension change issue" New topic
Author

struts2 default extension change issue

muthulingam Jayakanthan
Ranch Hand

Joined: Feb 27, 2005
Posts: 43
I have a following package tag in my struts.xml to redirect the root URL to my home.jsp. And I am not using web.xml <welcome-file-list>


<package name="default" namespace="/" extends="struts-default">
<action name="" class="actions.home.Home" method="execute">
<result name="success">/views/home.jsp</result>
</action>
</package>


So this is working well and opening the home.jsp page when I run the application.

Then I wanted to change the .action extension to .html using following line in the struts.xml

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

Now this is working for all my url except for the root redirection. I mean when I deply and run , it gives me page not found message in the browser and I can type and view other pages with .html extension.

Please help me modify my package tag ablove.



Regards

jklanka
Shashank Ag
Ranch Hand

Joined: Dec 22, 2009
Posts: 88

This is happening because, default behaviour of struts 2 is lookup for an entry in struts.xml when,
1. requested url has extension .action
2. or there is no extension at all.

Since request made on context root does not have any extension your page opens.
But, now you enforsed struts to lookup only when extension is .html hence its not working.

Do you have any good reason for not to use web.xml's welome-file-list


SCJP 91%, SCWCD 97%
muthulingam Jayakanthan
Ranch Hand

Joined: Feb 27, 2005
Posts: 43
Hi Thanks for the reply.

Without the line '<constant name="struts.action.extension" value="html"/>' I put the welcome list as below in web.xml

<welcome-file-list>
<welcome-file>Home.action</welcome-file>
</welcome-file-list>


Then in struts.xml I placed the following lines

<package name="default" namespace="/" extends="struts-default">
<action name="*" class="actions.home.Home" method="execute">
<result name="success">/views/home.jsp</result>
</action>
</package>


Now it is working fine.


But the issue is :-

If I put the following lines in struts.xml, then home page is not loading
<constant name="struts.action.extension" value="html"/>

Please help me what other modification I have to do. I need to replace my .action extension to .html

Regards

jklanka
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: struts2 default extension change issue
 
Similar Threads
Problem in action mapping
workflow problem
Struts2-json plugin not serializing action class to json
Struts 2 - wrong method executed
Struts2 + JSON : Getting Class Not Found Error