Struts2的配置文件,有些配置在項目中還是很實用的
struts.action.extension
The URL extension to use to determine if the request is meant for a Struts action
用URL擴展名來確定是否這個請求是被用作Struts action,其實也就是設(shè)置 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的完整連續(xù)的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開發(fā)模式
struts.dispatcher.parametersWorkaround
Whether to use a Servlet request parameter workaround necessary for some versions of WebLogic
(某些版本的weblogic專用)是否使用一個servlet請求參數(shù)工作區(qū)(PARAMETERSWORKAROUND)
struts.enable.DynamicMethodInvocation
Allows one to disable dynamic method invocation from the URL
允許動態(tài)方法調(diào)用
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
國際化信息內(nèi)碼
struts.i18n.reload
Whether the localization messages should automatically be reloaded
是否國際化信息自動加載
struts.locale
The default locale for the Struts application
默認的國際化地區(qū)信息
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
設(shè)置存儲上傳文件的目錄夾
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應(yīng)該使用自身的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過濾器中提供的靜態(tài)內(nèi)容應(yīng)該被瀏覽器緩存在頭部屬性中
struts.serve.static
Whether the Struts filter should serve static content or not
是否struts過濾器應(yīng)該提供靜態(tài)內(nèi)容
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
設(shè)置http端口
struts.url.https.port
The HTTPS port used by Struts URLs
設(shè)置https端口
struts.url.includeParams
The default includeParams method to generate Struts URLs
在url中產(chǎn)生 默認的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模版應(yīng)該被緩存
1:在action中定義的變量,在jsp頁面中顯示用:<s:property value="變量名" />
2:在頁面中實現(xiàn)自動增加的序號用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 ();
設(shè)置它們的值的方法
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:單選框和復(fù)選框的使用方法
1):可以設(shè)置默認選中值,注意list的值的設(shè)置,通過這種方式使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>構(gòu)成的字串(具體什么標簽生成什么,可以查看生成后的頁面的源代碼)如果不限制這些多余代碼的生成,頁面將變得無法控制,所以一般我們是不希望它生成多余的代碼的,具體的設(shè)置方法如果,在struts.xml中統(tǒng)一配置
<constant name="struts.ui.theme" value="simple"/>加上該句即可
也可以通過在頁面中將tag的theme屬性設(shè)為"simple"取消其默認的表格布局
不過最好是:自定義一個theme,并將其設(shè)為默認應(yīng)用到整個站點,如此一來就可以得到統(tǒng)一的站點風(fēng)格
7:jsp頁面中格式化日期的方法
<s:date name="unCarInsModificationInfo.createTime" format="yyyy-MM-dd" nice="false"/>這樣就可以將日期格式化為yyyy-MM-dd的形式
8:默認情況下,當請求action發(fā)生時,Struts運行時(Runtime)根據(jù)struts.xml里的Action映射集(Mapping),實例化action對應(yīng)的類,并調(diào)用其execute方法。當然,我們可以通過以下兩種方法改變這種默認調(diào)用
1)在classes/sturts.xml中新建Action,并指明其調(diào)用的方法
比如想調(diào)用action類中的
public String aliasAction() {
message ="自定義Action調(diào)用方法";
return SUCCESS;
}
則在classes/sturts.xml中加入下面代碼:
<action name="AliasHelloWorld" class="tutorial.HelloWorld" method="aliasAction">
<result>/HelloWorld.jsp</result>
</action>
既可用action名調(diào)用該方法了
2)(比較常用)
訪問Action時,在Action名后加上“!xxx”(xxx為方法名)。
9:Struts 2.0有兩個配置文件,struts.xml和struts.properties都是放在WEB-INF/classes/下。
struts.xml用于應(yīng)用程序相關(guān)的配置
struts.properties用于Struts 2.0的運行時(Runtime)的配置
10:在action類中取得web下某一文件夾物理路徑(絕對路徑)的方法
filePath = ServletActionContext.getServletContext().getRealPath("/upLoadFiles")
11:要想返回的頁面不是一個直接JSP頁面而是要先通過返回action中的方法讀取相應(yīng)的數(shù)據(jù)再返回到j(luò)sp頁面,有兩種方法
1)在struts.xml中這么設(shè)置
<result name="list" type="redirect-action">sysmanage/UserBaseInfoAction!findUserBaseInfo.action</result>
2)在action中返回時直接調(diào)用這個方法即可
return findList();
12:設(shè)置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" />