在struts中有很多常量可以配置,這些常量可以配置在struts.xml文件中葉可以配置在struts.properties中配置。
struts.xml中配置常量 <constant name="struts.action.extensiion" value="do"></constant> 這個常量是將struts的默認的 .action 改成 .do後綴名。
struts.properties中的配置如下:
struts.action.extension=do
此外因爲常量可以在下面多個配置文件中進行定義,所以我們需要了解struts2加載常量的搜索順序:
struts-default.xml
struts-plugin.xml
struts.xml
struts.properties
web.xml
如果在多個文件中配置了同一個常量,則後一個文件中配置的常量值會覆蓋前面文件中配置的常量值。
常用常量介紹:
·<constant name="struts.i18n.encoding" value="UTF-8" />
指定默認編碼集,作用於HttpServletRequest的setCharacterEncoding方法和freemarker、velocity的輸出
·<constant name="struts.action.extension" value="do" /> 改變action的後綴
·<constant name="struts.configuration.xml.reload" value="true" />
當struts的配置文件修改後,系統是否自動重新加載該文件,默認爲false,開發階段最好打開,這樣不用重啓服務器。
·<constant name="struts.devMode" value="true" />
開發模式下使用,這樣可以答應出更詳細的錯誤信息
·<constant name="struts.multipart.maxSize" value="10701096" />
上傳文件的大小限制,value值表示總大小,不是單個文件。
·<constant name="struts.ui.theme" value="simple" />
默認的視圖主題
·<constant name="struts.serve.static.browserCache" value="false" />
設置瀏覽器是否緩存靜態內容,默認爲true,開發階段最好關閉
·<constant name="struts.objectFactory" value="spring"/>
與spring集成時,指定由spring負責action對象的創建
·<constant name="struts.enable.DynamicMethodInvocation" value="true" />
該屬性設置struts2師傅支持動態方法調用,該屬性的默認值是true。如需關閉,則設置value="false"。