struts2配置檔案介紹
- 1. default.properties :用于配置struts 常量。例如:編碼
- 2. struts-default.xml :struts提供的預設核心配置檔案,struts大部分功能都在此配置檔案中。
-
3.struts-plugin.xml : struts插件核心配置檔案,struts整合其他架構或工具。
* 以上三個檔案,使用者自己不進行修改。
- 4. struts.xml :使用者自定義核心配置檔案。
- 5.struts.properties : 用于自定義struts常量配置檔案。一般不使用。
- 6.web.xml :也可以配置struts常量
- @@@注意:如果配置常量,所有的配置檔案存在優先級,編号越大優先級越高。
struts.xml的使用
struts.xml 可以配置所有内容,包括:常量
<!-- 通過初始化參數,配置常量 -->
<init-param>
<param-name>struts.i18n.encoding</param-name>
<param-value>GBK</param-value>
</init-param>
struts.xml标簽詳解:
标簽名稱 | 标簽參數 | 标簽用法 | 使用舉例 |
<constant> | name:struts提供固定常量名稱。此名稱從 default.properties檔案獲得 | 用于配置struts常量的 | <constant name="struts.devMode" value="true"></constant> |
value:常量值 | |||
<package> | name:給目前包進行唯一命名,必填項。用于其他包繼承的。 | struts用于管理所有action類 | <package name="struts-default" abstract="true"> 将struts已經完成的功能,作為一個包存在。名稱是固定值struts-default。 |
namespace:action通路路徑字首。 | 例如:"/" "/hello" "/a/b/c" "" | ||
extends:用于繼承其他包的。 | <package extends="struts-default"> 目前action繼承struts已經完成功能。 | ||
abstract:是否抽象,如果設定為true,表示沒有具體action實作功能。 | |||
<action> | name:action名稱,用于在請求路徑進行通路 | 用于配置action類(請求處理類) | |
class:action類全限定類名 | |||
method:用于确定action類中需要執行的方法,預設值:execute | |||
<result> | name:用于确定action類中,方法的傳回值 | 用于配置結果集 | |
text:标簽體用于設定jsp路徑 | |||
type:結果集類型( dispatcher:請求轉發,從一個action到jsp頁面,預設值。 redirect:重定向到jsp頁面 redirectAction:重定向到另一個action stream:以流的方法發送浏覽器,用于檔案下載下傳。 chain:鍊,在一次請求中,從一個action到另一個action) | |||
<result-types> | 用于配置結果集類型的,一般不用,但需要看的懂。 | ||
<interceptors> | 用于配置攔截器 | ||
<interceptor> | 用于注冊攔截器的 | ||
<interceptor-stack> | 攔截器棧,将已經注冊的攔截器組合在一起,形成一個棧。 | <interceptor-stack name="defaultStack"> 聲明一個攔截器棧,名稱是:defaultStack | |
<default-interceptor-ref> | 用于确定目前預設攔截器的 | <default-interceptor-ref name="defaultStack"/> 将“defaultStack”攔截器棧,聲明預設攔截器棧 | |
<default-action-ref> | 如果通路的action不存在,預設執行的aciton。 | /a/b/c/d/oneAction 此aciton沒有配置,預設情況傳回action找不到 如果配置<default-action-ref> 如果存在404時,不顯示action找不到,而是指定action | |
<default-class-ref > | 用于配置 預設action實作類 | <default-class-ref class="com.opensymphony.xwork2.ActionSupport" /> 如果編寫配置檔案時沒有聲明class屬性,及<action name=""> 将執行ActionSupport類。 | |
<include> | 将多個struts配置檔案組合成一個。 | struts.xml 入口配置檔案,大家共用的。用于存放通用子產品。 <include file="struts-user.xml" /> <include file="struts-book.xml" /> 提供子配置檔案 struts-user.xml struts-book.xml |
常見struts常量:
常見struts常量 | 常見struts常量的用法 |
struts.i18n.encoding=UTF-8 | 用于配置項目編碼 |
struts.objectFactory = spring | struts整合spring需要配置,預設注釋掉了 |
apache-commons-fileupload | struts預設使用檔案上傳解析工具 臨時檔案儲存位置 struts.multipart.saveDir= 上傳檔案最大大小,預設值:2M,機關位元組 struts.multipart.maxSize= |
struts.multipart.parser=jakarta | |
struts.action.extension=action | 用于設定action請求路徑擴充名。預設:action或空。多個值使用逗号分隔 例如:/hello/userAction 或 /hello/userAction.action |
struts.enable.DynamicMethodInvocation = false | 确定是否使用動态方法調用。預設關閉的。 |
struts.devMode = false | 設定開發模式,預設關閉。如果設定true:将提供更多提示資訊,自動加載檔案。 |
struts.i18n.reload = true | 自動重新加載國際化資源檔案。 |
struts.configuration.xml.reload = true | 自動沖洗加載xml配置檔案。例如:struts.xml。但不會自動加載action類。 |
struts.ui.theme=xhtml | 設定struts标簽主題,預設值:xhtml。取值:simple。 |