struts.xml配置文件的說明

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
 <!--
  constant:配置常量
   * name:指定的是struts2框架底層提供的default.properties資源文件中配置的"常量"
   * value:指定的是配置常量的值
   * 在struts.xml文件中,配置的常量的值會覆蓋底層提供的default.properties資源文件中配置的常量的值
  
  * 配置struts2框架的頁面中請求鏈接的後綴名,若是指定多個的話,用","隔開
  * 若是在struts.xml中和struts.properties資源文件中同時進行配置,struts.properties的配置起做用
  * 由於常量能夠在多個配置文件中進行定義,因此咱們須要瞭解下struts2加載常量的搜索順序:
   1 struts-default.xml
   2 struts-plugin.xml
   3 struts.xml
   4 struts.properties(本身建立)
   5 web.xml
  -->
 <!-- <constant name="struts.action.extension" value="do,love"></constant> -->
 
 <!-- 配置國際化資源文件修改時,是否從新加載。默認是false爲不加載,true是加載 -->
 <!-- <constant name="struts.i18n.reload" value="true"></constant> -->
 
 <!-- 配置struts2框架的配置文件修改時,是否從新加載。默認是false爲不加載,true是加載 -->
 <!-- <constant name="struts.configuration.xml.reload" value="true"></constant> -->
 
 <!--
  配置struts2框架的模式
   * 默認值是false,是生產模式
   * true是開發模式,須要更多的調試信息
    ### includes:
    ### - struts.i18n.reload = true
    ### - struts.configuration.xml.reload = true
  -->
 <constant name="struts.devMode" value="true"></constant>
 
 <!-- 配置動態方法調用,設置成不開啓。默認是true是開啓狀態;false是不開啓狀態 -->
 <constant name="struts.enable.DynamicMethodInvocation" value="false"></constant>
 
 <!--
  配置全部資源文件,省略後綴名,若是配置多個資源文件時,用","隔開。不只是國際化資源文件
  * 類型轉換器的錯誤提示資源文件
  * 國際化資源文件
  * 上傳文件的錯誤提示信息資源文件
  -->
 <constant name="struts.custom.i18n.resources"
   value="cn.itcast.converter.converter,
     cn.itcast.i18n.resources,
     cn.itcast.upload.fileuploadmessage,
     cn.itcast.ognl.resources">
 </constant>
 
 <!-- 配置文件上傳的總大小 -->
 <constant name="struts.multipart.maxSize" value="2097152000"></constant>
 
 <!-- 引入自定義配置文件 -->
 <include file="cn/itcast/primer/struts_primer.xml"></include>
 <include file="cn/itcast/resulttype/struts_resulttype.xml"></include>
 <include file="cn/itcast/pattern/struts_pattern.xml"></include>
 <include file="cn/itcast/converter/struts_converter.xml"></include>
 <include file="cn/itcast/context/struts_context.xml"></include>
 <include file="cn/itcast/i18n/struts_i18n.xml"></include>
 <include file="cn/itcast/upload/struts_upload.xml"></include>
 <include file="cn/itcast/aop/struts_aop.xml"></include>
 <include file="cn/itcast/validate/struts_validate.xml"></include>
 <include file="cn/itcast/ognl/struts_ognl.xml"></include>
 
 
</struts>web

 

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
 "-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
 "http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
 <!-- /primer/helloWorldAction.action
  package:包
   * name:包名,惟一的,必選項
   * namespace:命名空間,惟一的,至關於房間號。可選項,省略狀況下是"/"。頁面中請求鏈接的前半部分
   * extends:繼承
    * extends="struts-default":struts2框架底層提供的核心包struts2-core-2.3.3.jar下的struts-default.xml文件
    * 爲何要繼承這個struts-default.xml文件?
     * 由於struts2框架底層提供的struts-default.xml聲明瞭全部的攔截器和攔截器棧,
          知道在struts2框架運行時執行struts-default.xml文件中的攔截器棧。
     * 若是不繼承struts-default.xml文件,就沒有辦法使用struts2框架提供的全部攔截器
  -->
 <package name="primer" namespace="/primer" extends="struts-default">
  
  <!--
   若是找不到對應的action名的時候,配置默認要執行的action
    * name:指定action的名稱
  -->
  <default-action-ref name="helloWorldAction" />
  
  <!--
   action:
    * name:對應頁面中請求鏈接的後面半部分
    * class:對應要執行的類的完整路徑
   -->
  <action name="helloWorldAction" class="cn.itcast.primer.HelloWorldAction">
   <!--
    result:結果類型
     * name:對應的是執行的類的方法的返回值
      public String execute() throws Exception {
       System.out.println("HelloWorldAction ************* execute()");
       return "success";
      }
     * 後半部分的文本內容:要轉向到的頁面
    -->
   <result name="success">/primer/success.jsp</result>
  </action>
  <!--
   沒有爲action指定class
    * 在struts2框架底層的struts-default.xml文件中,配置了默認執行的類
     com.opensymphony.xwork2.ActionSupport
      public String execute() throws Exception {
             return SUCCESS;
         }
    * 實際上,默認執行的是底層提供的ActionSupport類的execute()方法
    * result結果類型,默認是根據struts2框架底層提供的ActionSupport類的execute()方法返回值,進行跳轉
   -->
  <action name="actionNoClass">
   <result name="success">/primer/success.jsp</result>
  </action>
 </package>
</struts>apache

相關文章
相關標籤/搜索