在Struts2中,所有动作类有一个默认的后缀 .action 扩展。 例如,
<struts>
  <package name="default" namespace="/" extends="struts-default">
	<action name="SayStruts2">
		<result>pages/printStruts2.jsp</result>
	</action>
  </package>
</struts>
如要访问“SayStruts2”动作类,需要使用以下网址:
Action URL : http://localhost:8080/Struts2Example/SayStruts2.action
配置动作扩展
Struts 2是允许配置扩展名的,要对其进行更改,只需要声明一个常数“struts.action.extension”值:

1. html 扩展

更改动作类为 .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”动作类,使用如下URL:
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>
现在,可以通过如下的URL来访问“SayStruts2' 动作类:
Action URL : http://localhost:8080/Struts2Example/SayStruts2

相关文章:

  • 2021-04-24
  • 2021-04-09
  • 2021-07-11
  • 2022-01-08
  • 2022-12-23
  • 2021-08-13
  • 2022-12-23
  • 2021-10-15
猜你喜欢
  • 2021-05-19
  • 2022-12-23
  • 2021-06-18
  • 2022-12-23
  • 2021-08-03
  • 2021-09-12
  • 2021-12-10
相关资源
相似解决方案