Struts2的參數配置說明

一、Struts2配置文件
Struts2相關的配置文件有web.xml,struts.xml,struts.properties,
struts-default.xml,velocity.properties,struts-default.vm。其中web.xml,struts.xml是必須的,其它的配置文件可選擇。它們在web應用中的功能如下:
web.xml:包含所有必須的框架組件的web部署描述符。
Struts.xml:配置包含result/view類型、action映射、攔截器等的Struts2的主要配置文件。
Struts.properties:配置struts2的框架屬性。
Struts-default.xml:在文件在struts-action-x.x.jar中,該文件是應該被包含在struts.xml中的缺省配置。
Welocity.properties:重寫了velocity的配置文件。
Struts-default.vm:相對於velocity的缺省配置。

二、Struts2配置元素
Struts2核心的配置文件是缺省的struts.xml。
必要的時候,缺省的配置文件可以包含其它的配置文件;struts文件可以放入jar中,並自動插入應用程序,這樣每個模塊可以包含自己的配置文件並自動配置。在Freemarker和Velocity模塊中,模板也能從classpath中加載,所以整個模塊可以作爲一個簡單的jar文件被包含。
Struts.xml配置文件可以包含Interceptor、Action類和Results。
Struts.xml配置元素說明:

1、Packages
Packages:packages把actions、results、results types、interceptors
和interceptor-stacks組裝到一個邏輯單元中,從概念上講,packages就像一個對象,可以被其它子包從寫,而且可以擁有自己獨立的部分。
Name屬性是packages的必填元素,它作爲一個關鍵字被後邊的包引用;extends元素是可選的,它允許包擴展一個和多個前邊定義的包。注意,
struts.xml文件是至上而下處理的,所有被擴展的包,需要在擴展包前定義。
Abstract元素是可選的,它可以申明一個不包含actions的配置文件。

2、Namespace
Namespace元素把actions細分到邏輯模塊,每一個namespace都有自己的
前綴(prefix),namespace避免了action之間的名字衝突,當前綴出現在URI中時,這些標籤都是名字空間感知的(“namespace aware”),所以這些namespace prefix不必嵌入到表單或連接中。
Default的namespace是一個空字符串“”,如果在指定的配置文件中,沒有找到action,缺省的namespace也會被查找。 Local/global策略允許應用程序在action “extends”元素層次結構之外,有全局的action配置。缺省的namespace也可以不在package中申明。
Namespace prefix可以註冊爲java的申明式安全,以確保授權的用戶才能訪問namespace的資源。
Root namespace(“/”)也被支持,root就是當直接請求context path的時候的namespace。

[個人理解:namespace的用法就像struts1.x中的path一樣,只不過它在package中什麼路徑,而在action中申明action名子罷了]

3、Include
Include元素使得框架能應用“divide and conquer”來配置文件。被include
的每個配置文件必須和struts.xml有一樣的格式,一個大的項目可以採用這樣方式來組織程序模塊。
Include元素也可以和package交替出現,框架將按照順序加載配置文件。

4、Interceptor configuration
Interceptor允許應用程序在Action方法執行前後定義執行代碼,
Interceptor在應用程序開發中十分重要,對於Interceptor有許多用例,如validation, property population, security, logging, 和profiling。
Interceptor被定義爲一個Java類,Interceptor也可以組裝成Interceptor-stack,他們將按照定義的順序執行。
在struts-default.xml中定義了一些缺省的Interceptor-stack,以便框架能很好地運行。

5、Action
Action是框架的“工作單元”。Action可以指定一個Interceptor-stack、
一序列的return type和一序列的異常處理,但只有name屬性是必須的。
 
配置參數說明如下:
struts.action.extension
           The URL extension to use to determine if the request is meant for a Struts action
            用URL擴展名來確定是否這個請求是被用作Struts action,其實也就是設置 action的後綴,例如login.do的'do'字。
struts.configuration
           The org.apache.struts2.config.Configuration implementation class
             org.apache.struts2.config.Configuration接口名
struts.configuration.files
           A list of configuration files automatically loaded by Struts
            struts自動加載的一個配置文件列表
struts.configuration.xml.reload
           Whether to reload the XML configuration or not
            是否加載xml配置(true,false)
struts.continuations.package
            The package containing actions that use Rife continuations
            含有actions的完整連續的package名稱
struts.custom.i18n.resources
           Location of additional localization properties files to load
            加載附加的國際化屬性文件(不包含.properties後綴)
struts.custom.properties
           Location of additional configuration properties files to load
            加載附加的配置文件的位置
struts.devMode
           Whether Struts is in development mode or not
            是否爲struts開發模式
struts.dispatcher.parametersWorkaround
           Whether to use a Servlet request parameter workaround necessary for some versions of WebLogic
             (某些版本的weblogic專用)是否使用一個servlet請求參數工作區(PARAMETERSWORKAROUND)
struts.enable.DynamicMethodInvocation
           Allows one to disable dynamic method invocation from the URL
             允許動態方法調用
struts.freemarker.manager.classname
           The org.apache.struts2.views.freemarker.FreemarkerManager implementation class
            org.apache.struts2.views.freemarker.FreemarkerManager接口名
struts.i18n.encoding
           The encoding to use for localization messages
            國際化信息內碼
struts.i18n.reload
           Whether the localization messages should automatically be reloaded
            是否國際化信息自動加載
struts.locale
           The default locale for the Struts application
            默認的國際化地區信息
struts.mapper.class
           The org.apache.struts2.dispatcher.mapper.ActionMapper implementation class
             org.apache.struts2.dispatcher.mapper.ActionMapper接口
struts.multipart.maxSize
           The maximize size of a multipart request (file upload)
            multipart請求信息的最大尺寸(文件上傳用)
struts.multipart.parser
           The org.apache.struts2.dispatcher.multipart.MultiPartRequest parser implementation for a multipart request (file upload)
           專爲multipart請求信息使用的org.apache.struts2.dispatcher.multipart.MultiPartRequest解析器接口(文件上傳用)
struts.multipart.saveDir
           The directory to use for storing uploaded files
            設置存儲上傳文件的目錄夾
struts.objectFactory
           The com.opensymphony.xwork2.ObjectFactory implementation class
            com.opensymphony.xwork2.ObjectFactory接口(spring)
struts.objectFactory.spring.autoWire
           Whether Spring should autoWire or not
            是否自動綁定Spring
struts.objectFactory.spring.useClassCache
           Whether Spring should use its class cache or not
            是否spring應該使用自身的cache
struts.objectTypeDeterminer
           The com.opensymphony.xwork2.util.ObjectTypeDeterminer implementation class
             com.opensymphony.xwork2.util.ObjectTypeDeterminer接口
struts.serve.static.browserCache
           If static content served by the Struts filter should set browser caching header properties or not
            是否struts過濾器中提供的靜態內容應該被瀏覽器緩存在頭部屬性中
struts.serve.static
           Whether the Struts filter should serve static content or not
            是否struts過濾器應該提供靜態內容
struts.tag.altSyntax
           Whether to use the alterative syntax for the tags or not
            是否可以用替代的語法替代tags
struts.ui.templateDir
           The directory containing UI templates
            UI templates的目錄夾
struts.ui.theme
           The default UI template theme
            默認的UI template主題
struts.url.http.port
           The HTTP port used by Struts URLs
            設置http端口
struts.url.https.port
           The HTTPS port used by Struts URLs
            設置https端口
struts.url.includeParams
           The default includeParams method to generate Struts URLs
           在url中產生 默認的includeParams
struts.velocity.configfile
           The Velocity configuration file path
            velocity配置文件路徑
struts.velocity.contexts
           List of Velocity context names
            velocity的context列表
struts.velocity.manager.classname
           org.apache.struts2.views.velocity.VelocityManager implementation class
            org.apache.struts2.views.velocity.VelocityManager接口名
struts.velocity.toolboxlocation
           The location of the Velocity toolbox
            velocity工具盒的位置
struts.xslt.nocache
           Whether or not XSLT templates should not be cached
            是否XSLT模版應該被緩存
在Struts2中,action中的getXXX()只在服務器啓動時執行一次,一刷新頁面顯示的數據內容全都沒了,這種問題的解決辦法是:
在web.xml中配置struts2.0時,
<filter-mapping>
<filter-name>action2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
把/*改成*.ation就OK了
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章