在Struts2中,Action的默認後綴是.action,在直接訪問一個Action時,如超級鏈接等,必須寫成actionName.action的形式,但如果用Struts的Form標籤,則在Form的action屬性中不能加.action,後綴會自動加上。
如果想把後綴改成.do,把web.xml文件中的過濾器修改爲.do,是不能達到目的的,因爲這裏只是定義哪些鏈接會被Struts2框架捕獲,如下:
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>*.do</url-pattern>
</filter-mapping>
解決方法是在WEB-INFclasses下添加一個文本文件:struts.properties,裏面添加一行:struts.action.extension=do,此文件如果在MyEclipse中,可以放在src目錄下。
也可以在struts.xml文件中定義:
<struts>
........
<constant name="struts.action.extension" value="do"/>
</struts>