Pages Navigation Menu

Coding is much easier than you think

Remove .action extension in struts2 and to give user defined extension

Remove .action extension in struts2 and to give user defined extension

 
In Older version of Struts 2, all action class by default has .action as extension,
 
For example, by default to access an action say €œLoginAction class, we will use the following URL
 

Action URL: http://localhost:8089/Struts2/Login.action

 
In its latest version i.e version after 2.2.x by default action class has no extension, in this case the default wat to access an action is
 

Action URL: http://localhost:8089/Struts2/Login

 
This article aims to change this default extension.
 
** UPDATE: Struts 2 Complete tutorial now available here.
 
So in order to remove or to give any user defined extension, just declare a constant “struts.action.extension”€ in struts.xml and set the value to the extension you wish.
 
For example to change the extension from .action to .jsp, the following code is used.

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

 
Output URL will be shown like this:-
 

Action URL: http://localhost:8089/Struts2/Login.jsp

 
Suppose If you want to shown empty extension URL try this:-

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

 
Output URL will be shown like this:-

 

Action URL: http://localhost:8089/Struts2/Login

 
Hope This Help You :)
 
Article to read Next:

 

About Mohaideen Jamil


Am currently working as a Struts 2 Developer in a reputed IT Organisations. I can help you with teaching Core java and Struts 2. Follow me on Facebook or Google Plus. If you like my tutorials, consider making a donation to this charity, thanks.