如何刪除Struts2動作的尾碼擴展名

在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


上一篇: Struts2開發者模式 下一篇: 使用Struts2動作