Struts常量
Struts中默認訪問后綴:
Struts1中默認訪問后綴是*.do
Struts2中默認訪問后綴是*.action
如何修改默認訪問后綴
1、Struts2的.action訪問后綴在哪里定義?
Struts-core-2.3.4-1.jar/org.apache.struts/default.PRopertles
Struts.action.extendsion=action..
2、在struts.xml中通過常量修改
<constant name=”struts.action.extension” value=”action,do,”></constant>
指定訪問后綴為action/do/沒有訪問后綴都可以
Value=”action,do,” 訪問后綴:action/do/不帶后綴
Value=”action,do” 訪問后綴:action或do
Value=”action” 訪問后最:action
常量:
a、 指定默認編碼集,作用于HttpServletRequest的setCharacterEncoding方法 和freemarker 、velocity的輸出(post有效)
<constant name="struts.i18n.encoding" value="UTF-8"/>
b、自定義后綴修改常量
<constant name="struts.action.extension" value="do"/>
c、設置瀏覽器是否緩存靜態內容,默認值為true(生產環境下使用),開發階段最好關閉
<constant name="struts.serve.static.browserCache" value="false"/>
d、當struts的配置文件修改后,系統是否自動重新加載該文件,默認值為false(生產環境下使用),開發階段最好打開
<constant name="struts.configuration.xml.reload" value="true"/>
e、開發模式下使用,這樣可以打印出更詳細的錯誤信息
<constant name="struts.devMode" value="true" />
f、默認的視圖主題
<constant name="struts.ui.theme" value="simple" />
g、與spring集成時,指定由spring負責action對象的創建
<constant name="struts.objectFactory" value="spring" />
h、該屬性設置Struts 2是否支持動態方法調用,該屬性的默認值是true。如果需要關閉動態方法調用,則可設置該屬性為false
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
作用:
當我們配置**.xml文件的action時,可以不配置method,可以直接通過訪問地址訪問指定的method
如:
我問需要訪問hello-->login()
方法一:配置method
http://localhost:8080/StrutStu/hello
方法二:通過動態方法訪問
http://localhost:8080/StrutStu/hello!login
i、上傳文件的大小限制
<constant name="struts.multipart.maxSize" value=“10701096"/>
配置全局跳轉視圖
<!-- 配置全局跳轉視圖 --> <global-results> <result name="login">/success.jsp</result> </global-results> <action name="hello" class="cn.lfsenior.c_config.HelloWord" method="login" > <!-- 返回結果標記login對應的頁面在當前action中沒有配置 所以會去找全局配置是否有login標記對應的頁面 --> </action>配置各項默認值
<!-- 配置各項默認值 --> <!-- name 只配置了訪問路徑名稱 class 默認執行的action在struts-default有配置 <default-class-ref class="com.opensymphony.xwork2.ActionSupport" /> method 默認為execute 默認的方法execute返回值為success,對應的頁面去全局視圖找。 --> <action name="test"></action> <!-- 什么情況不配置class? 即處理的aciton --> <!-- 答案: 當只是需要跳轉到WEB-INF下資源的時候。(WEB-INF下的資源只對服務端開發,不對客戶端開發。所以只能通過轉發訪問,不能通過重定向訪問) --> <action name="test2"> <result name="success" type="redirect">/WEB-INF/index.jsp</result> </action>
新聞熱點
疑難解答