掌握 Struts 2 配置檔案架構:struts.xml 模組化拆分、Servlet 2.3/2.4 容器相容性實測、插件 Jar 自動載入機制、屬性配置雙模式(struts.properties vs struts.xml constant)、熱重載關鍵開關。
ServletDispatcher,映射 *.actionxwork.xml ↔ struts.xml、webwork.properties ↔ struts.properties,內容幾乎相同,僅關鍵字差異struts.xml 關鍵映射<action name="..."> 相當於 Struts 1 <action path="...">,**不需以 / 開頭**Action 使用業務邏輯元件通常不直接 new,透過工廠方法或 IOC 容器。WebWork 有內建 IOC,但 Struts 2 慣用 Spring IOC。
struts.xml 模組化拆分可拆分為多檔:struts-part1.xml、struts-part2.xml...,主檔 <include file="struts-part1.xml"/> 引入。參考 struts2-core.jar 內 struts-default.xml 內建大量預設配置。
官方要求 Servlet 2.4/JSP 2.0 容器。實測簡單範例(web-app_2_3.dtd)在 Tomcat 4.1.30(Servlet 2.3/JSP 1.2)可正常運行,潛在問題未知。
struts2-xxx-plugin.jar 內含 struts-plugin.xml(即 struts.xml 格式)。放入 WEB-INF/lib 自動載入。struts.properties 中 struts.configuration.files=struts-default.xml,struts-plugin.xml,struts.xml 定義載入順序。可自製插件 Jar。
struts.properties)struts.action.extensionstruts.serve.static.browserCachestruts.enable.SlashesInActionNamesstruts.devModestruts.i18n.reloadstruts.configuration.xml.reloadstruts.custom.i18n.resourcesstruts.i18n.encoding多值支援逗號分隔。預設值在 default.properties。
預設 *.action。修改 struts.action.extension=unmi,action → *.unmi 和 *.action 皆由 Struts 2 處理。
struts.xml 自動生效struts.i18n.reload=true 即可熱重載struts.properties 檔案struts.xml 中 <constant name="struts.i18n.reload" value="true"/>大多數開發者傾向 struts.properties。