在struts2中,所有的action类都有一个默认的后缀xx.action。例如:
如果要访问 "SayStrute2" action类,使用如下的URL:
struts2t是允许配置默认后缀的
1 html后缀
此时访问"SayStruts2"action类可以通过:
2 无后缀
此时访问"SayStruts2"action类可以通过:
- <struts>
- <package name="default" namespace="/" extends="struts-default">
- <action name="SayStruts2">
- <result>pages/printStruts2.jsp</result>
- </action>
- </package>
- </struts>
如果要访问 "SayStrute2" action类,使用如下的URL:
- Action URL : http://localhost:8080/Struts2Example/SayStruts2.action
struts2t是允许配置默认后缀的
1 html后缀
- <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>
此时访问"SayStruts2"action类可以通过:
- Action URL : http://localhost:8080/Struts2Example/SayStruts2.html
2 无后缀
- <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>
此时访问"SayStruts2"action类可以通过:
- Action URL : http://localhost:8080/Struts2Example/SayStruts2
本文介绍了Struts2框架中如何配置URL后缀,包括默认的.action后缀、自定义为.html后缀以及无后缀的配置方式。通过示例展示了不同配置下访问Action的方法。

1224

被折叠的 条评论
为什么被折叠?



