In Struts 2, all action class has a default suffix .action
extension. For example,
<struts>
<package name="default" namespace="/" extends="struts-default">
<action name="SayStruts2">
<result>pages/printStruts2.jsp</result>
</action>
</package>
</struts>
To access the “SayStruts2
″ action class, use the following URL :
Action URL : http://localhost:8080/Struts2Example/SayStruts2.action
Configure the action extension
Struts 2 is allow to configure the action extension easily, to change it, just declare a constant “struts.action.extension
” value :
1. html extension
Change the action class to .html
extension.
<struts>
<constant name="struts.action.extension" value="html"/>
<package name="default" namespace="/" extends="struts-default">
<action name="SayStruts2">
<result>pages/printStruts2.jsp</result>
</action>
</package>
</struts>
Now you can access the “SayStruts2
″ action class via
Action URL : http://localhost:8080/Struts2Example/SayStruts2.html
2. No extension
Change the action class to empty extension.
<struts>
<constant name="struts.action.extension" value=""/>
<package name="default" namespace="/" extends="struts-default">
<action name="SayStruts2">
<result>pages/printStruts2.jsp</result>
</action>
</package>
</struts>
Now you can access the “SayStruts2
′ action class via
Action URL : http://localhost:8080/Struts2Example/SayStruts2