天天看點

struts2 屬性配置檔案

Struts2的配置檔案,有些配置在項目中還是很實用的

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模版應該被緩存

1:在action中定義的變量,在jsp頁面中顯示用:<s:property value="變量名" />

2:在頁面中實作自動增加的序号用iterator的statuts的index屬性 eg:

<s:iterator value="#request.inOutAccountList" id="data" status="listStat">

<s:property value="#listStat.index+1"/>

</s:iterator>

3:在action類中取得request和session對象的方法

Map session = ActionContext.getContext().getSession();

HttpServletRequest request = ServletActionContext.getRequest ();

設定它們的值的方法

session.put("operation", "add");

request.setAttribute("name", name);

頁面中取得它們的值:

<s:property value="#session.operation"/>

<s:property value="#request.name"/>

4:頁面中奇偶行樣式不一樣的控制方法:

<tr class="<s:if test='#listStat.odd == true '>tableStyle-tr1</s:if><s:else>tableStyle-tr2</s:else>" >

5:單選框和複選框的使用方法

1):可以設定預設選中值,注意list的值的設定,通過這種方式使key和value不一樣,這種方法比較常用(checkboxlist or radio)

<s:radio name="uncarInsPolicy.policyStateCode"

list="#{'5':'通過' , '2':'不通過'}"

listKey="key"

listValue="value"

value='5'

/>

2):這裡的key和value的值是一樣的(checkboxlist or radio)

<s:checkboxlist

list="{'Red', 'Blue', 'Green'}"

name="favoriteColor"/>

6:struts2 中的标簽會生成類似由<tr><td></td></tr>構成的字串(具體什麼标簽生成什麼,可以檢視生成後的頁面的源代碼)如果不限制這些多餘代碼的生成,頁面将變得無法控制,是以一般我們是不希望它生成多餘的代碼的,具體的設定方法如果,在struts.xml中統一配置

<constant name="struts.ui.theme" value="simple"/>加上該句即可

也可以通過在頁面中将tag的theme屬性設為"simple"取消其預設的表格布局

不過最好是:自定義一個theme,并将其設為預設應用到整個站點,如此一來就可以得到統一的站點風格

7:jsp頁面中格式化日期的方法

<s:date name="unCarInsModificationInfo.createTime" format="yyyy-MM-dd" nice="false"/>這樣就可以将日期格式化為yyyy-MM-dd的形式

8:預設情況下,當請求action發生時,Struts運作時(Runtime)根據struts.xml裡的Action映射集(Mapping),執行個體化action對應的類,并調用其execute方法。當然,我們可以通過以下兩種方法改變這種預設調用

1)在classes/sturts.xml中建立Action,并指明其調用的方法

比如想調用action類中的

public String aliasAction() {

message ="自定義Action調用方法";

return SUCCESS;

}

則在classes/sturts.xml中加入下面代碼:

<action name="AliasHelloWorld" class="tutorial.HelloWorld" method="aliasAction">

<result>/HelloWorld.jsp</result>

</action>

既可用action名調用該方法了

2)(比較常用)

通路Action時,在Action名後加上“!xxx”(xxx為方法名)。

9:Struts 2.0有兩個配置檔案,struts.xml和struts.properties都是放在WEB-INF/classes/下。

struts.xml用于應用程式相關的配置

struts.properties用于Struts 2.0的運作時(Runtime)的配置

10:在action類中取得web下某一檔案夾實體路徑(絕對路徑)的方法

filePath = ServletActionContext.getServletContext().getRealPath("/upLoadFiles")

11:要想傳回的頁面不是一個直接JSP頁面而是要先通過傳回action中的方法讀取相應的資料再傳回到jsp頁面,有兩種方法

1)在struts.xml中這麼設定

<result name="list" type="redirect-action">sysmanage/UserBaseInfoAction!findUserBaseInfo.action</result>

2)在action中傳回時直接調用這個方法即可

return findList();

12:設定checkboxlist中預設值的方法

<s:checkboxlist name="skills1"

="Skills 1"

list="{ 'Java', '.Net', 'RoR', 'PHP' }"

value="{ 'Java', '.Net' }" />

<s:checkboxlist name="skills2"

label="Skills 2"

list="#{ 1:'Java', 2: '.Net', 3: 'RoR', 4: 'PHP' }"

listKey="key"

listValue="value"

value="{ 1, 2, 3 }"/>

13:二級級連下拉框

<s:set name="foobar"

value="#{'Java': {'Spring', 'Hibernate', 'Struts 2'}, '.Net': {'Linq', ' ASP.NET 2.0'}, 'Database': {'Oracle', 'SQL Server', 'DB2', 'MySQL'}}" />

<s:doubleselect list="#foobar.keySet()"

doubleName="technology"

doubleList="#foobar[top]"

label="Technology" />