??xml version="1.0" encoding="utf-8" standalone="yes"?> struts.action.extension struts.serve.static.browserCache 该属性设|浏览器是否~存静态内宏V当应用处于开发阶D|Q我们希望每ơ请求都获得服务器的最新响应,则可讄该属性ؓfalse?/p>
struts.enable.DynamicMethodInvocation 该属性设|Struts 2是否支持动态方法调用,该属性的默认值是true。如果需要关闭动态方法调用,则可讄该属性ؓfalse?/p>
struts.enable.SlashesInActionNames 该属性设|Struts 2是否允许在Action名中使用斜线Q该属性的默认值是false。如果开发者希望允许在Action名中使用斜线Q则可设|该属性ؓtrue?/p>
struts.tag.altSyntax 该属性指定是否允许在Struts 2标签中用表辑ּ语法Q因为通常都需要在标签中用表辑ּ语法Q故此属性应该设|ؓtrueQ该属性的默认值是true?/p>
struts.devMode该属性设|Struts 2应用是否使用开发模式。如果设|该属性ؓtrueQ则可以在应用出错时昄更多、更友好的出错提C。该属性只接受true和flase两个|该属性的默认值是false。通常Q应用在开发阶D,该属性设|ؓtrueQ当q入产品发布阶段后,则该属性设|ؓfalse?/p>
struts.i18n.reload该属性设|是否每ơHTTPh到达Ӟpȝ都重新加载资源文件。该属性默认值是false。在开发阶D将该属性设|ؓtrue会更有利于开发,但在产品发布阶段应将该属性设|ؓfalse?/p>
提示 开发阶D将该属性设|了trueQ将可以在每ơ请求时都重新加载国际化资源文gQ从而可以让开发者看到实时开发效果;产品发布阶段应该该属性设|ؓfalseQ是Z提供响应性能Q每ơ请求都需要重新加载资源文件会大大降低应用的性能?/p>
struts.ui.theme该属性指定视图标{N认的视图主题Q该属性的默认值是xhtml?/p>
struts.ui.templateDir该属性指定视图主题所需要模板文件的位置Q该属性的默认值是templateQ即默认加蝲template路径下的模板文g?/p>
struts.ui.templateSuffix该属性指定模板文件的后缀Q该属性的默认属性值是ftl。该属性还允许使用ftl、vm或jspQ分别对应FreeMarker、Velocity和JSP模板?/p>
struts.configuration.xml.reload该属性设|当struts.xml文g改变后,pȝ是否自动重新加蝲该文件。该属性的默认值是false?/p>
struts.velocity.configfile该属性指定Velocity框架所需的velocity.properties文g的位|。该属性的默认gؓvelocity.properties?/p>
struts.velocity.contexts该属性指定Velocity框架的Context位置Q如果该框架有多个ContextQ则多个Context之间以英文逗号Q?Q隔开?/p>
struts.velocity.toolboxlocation该属性指定Velocity框架的toolbox的位|?/p>
struts.url.http.port该属性指定Web应用所在的监听端口。该属性通常没有太大的用P只是当Struts 2需要生成URLӞ例如Url标签Q,该属性才提供Web应用的默认端口?/p>
struts.url.https.port该属性类gstruts.url.http.port属性的作用Q区别是该属性指定的是Web应用的加密服务端口?/p>
struts.url.includeParams该属性指定Struts 2生成URL时是否包含请求参数。该属性接受none、get和all三个属性|分别对应于不包含、仅包含GETcdh参数和包含全部请求参数?/p>
struts.freemarker.manager.classname 该属性指定Struts 2使用的FreeMarker理器。该属性的默认值是 org.apache.struts2.views.freemarker.FreemarkerManagerQ这是Struts 2内徏的FreeMarker理器?/p>
struts.freemarker.wrapper.altMap该属性只支持true和false两个属性|默认值是true。通常无需修改该属性倹{?/p>
struts.xslt.nocache 该属性指定XSLT Result是否使用样式表缓存。当应用处于开发阶D|Q该属性通常被设|ؓtrueQ当应用处于产品使用阶段Ӟ该属性通常被设|ؓfalse?/p>
struts.configuration.files 该属性指定Struts 2框架默认加蝲的配|文Ӟ如果需要指定默认加载多个配|文Ӟ则多个配|文件的文g名之间以英文逗号Q?Q隔开。该属性的默认gؓstruts- default.xml,struts-plugin.xml,struts.xmlQ看到该属性|读者应该明白ؓ什么Struts 2框架默认加蝲struts.xml文g了?/p>
2
3 import javax.servlet.FilterChain;
4 import javax.servlet.ServletException;
5 import javax.servlet.ServletRequest;
6 import javax.servlet.ServletResponse;
7 import javax.servlet.http.HttpServletRequest;
8
9 import org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter;
10
11 public class StrutsAndFckFilter extends StrutsPrepareAndExecuteFilter {
12
13 @Override
14 public void doFilter(ServletRequest request, ServletResponse response,
15 FilterChain chain) throws IOException, ServletException {
16
17 HttpServletRequest httpRequest=(HttpServletRequest)request;
18
19 if("/fckeditor/editor/filemanager/connectors".equals(httpRequest.getServletPath())){
20 chain.doFilter(request, response);
21 }else{
22 super.doFilter(request, response, chain);
23 }
24 }
25
26 }
27
内容?connector.userActionImpl=net.fckeditor.requestcycle.impl.EnabledUserAction
3. 修改web.xml
2 <filter-name>struts2</filter-name>
3 <filter-class>com.capinfo.cms.common.filter.StrutsAndFckFilter</filter-class>
4 </filter>
5 <servlet>
6 <servlet-name>ConnectorServlet</servlet-name>
7 <servlet-class>
8 net.fckeditor.connector.ConnectorServlet
9 </servlet-class>
10 <load-on-startup>1</load-on-startup>
11 </servlet>
12
13 <servlet-mapping>
14 <servlet-name>ConnectorServlet</servlet-name>
15 <!-- Do not wrap this line otherwise Glassfish will fail to load this file -->
16 <url-pattern>/fckeditor/editor/filemanager/connectors/*</url-pattern>
17 </servlet-mapping>
]]>
]]>
1Q?W号的用途一般有三种?br />
1)讉K非根对象属性,例如CZ中的#session.msg表达式,׃Struts
2中值栈被视为根对象Q所以访问其他非根对象时Q需要加#前缀。实际上Q?相当于ActionContext.
getContext()Q?session.msg表达式相当于ActionContext.getContext().getSession().
getAttribute(”msg”) ?br />
2)用于qo和投影(projectingQ集合,如示例中的persons.{?#this.age>20}?br />
3)用来构造MapQ例如示例中?{'foo1':'bar1','foo2':'bar2'}?br />
2Q?W号
%W号的用途是在标志的属性ؓ字符串类型时Q计OGNL表达式的倹{如下面的代码所C:
构造Map
<s:set name="foobar" value="#{'foo1':'bar','foo2':'bar2'}" />
<p>The value of key "foo1" is <s:property value="#foobar['foo1']" /></p>
<p>不用%Q?lt;s:url value="#foobar['foo1']" /></p>
<p>使用Q:<s:url value="%{#foobar['foo1']}" /></p>
3Q?W号
$W号主要有两个方面的用途?br />
在国际化资源文g中,引用OGNL表达式,例如国际化资源文件中的代码:reg.agerange=国际化资源信息:q龄必须?{min}?{max}之间?br />
在Struts 2框架的配|文件中引用OGNL表达式,例如下面的代码片断所C:
<validators>
<field name=”intb”>
<field-validator type=”int”>
<param name=”min”>10</param>
<param name=”max”>100</param>
<message>BAction-test校验Q数字必Mؓ${min}?{max}之间Q?lt;/message>
</field-validator>
</field>
</validators>
]]>
The URL extension to use to determine if the request is meant for a Struts action
用URL扩展名来定是否q个h是被用作Struts actionQ其实也是讄 action的后~Q例如login.do?do'字?br />
struts.configuration
The org.apache.struts2.config.Configuration implementation class
org.apache.struts2.config.Configuration接口?br />
struts.configuration.files
A list of configuration files automatically loaded by Struts
struts自动加蝲的一个配|文件列?br />
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的完整连l的package名称
struts.custom.i18n.resources
Location of additional localization properties files to load
加蝲附加的国际化属性文Ӟ不包?properties后缀Q?br />
struts.custom.properties
Location of additional configuration properties files to load
加蝲附加的配|文件的位置
struts.devMode
Whether Struts is in development mode or not
是否为struts开发模?br />
struts.dispatcher.parametersWorkaround
Whether to use a Servlet request parameter workaround necessary for some versions of WebLogic
Q某些版本的weblogic专用Q是否用一个servleth参数工作区(PARAMETERSWORKAROUNDQ?br />
struts.enable.DynamicMethodInvocation
Allows one to disable dynamic method invocation from the URL
允许动态方法调?br />
struts.freemarker.manager.classname
The org.apache.struts2.views.freemarker.FreemarkerManager implementation class
org.apache.struts2.views.freemarker.FreemarkerManager接口?br />
struts.i18n.encoding
The encoding to use for localization messages
国际化信息内?br />
struts.i18n.reload
Whether the localization messages should automatically be reloaded
是否国际化信息自动加?nbsp;
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)
multiparth信息的最大尺寸(文g上传用)
struts.multipart.parser
The org.apache.struts2.dispatcher.multipart.MultiPartRequest parser implementation for a multipart request (file upload)
专ؓmultiparth信息使用的org.apache.struts2.dispatcher.multipart.MultiPartRequest解析器接口(文g上传用)
struts.multipart.saveDir
The directory to use for storing uploaded files
讄存储上传文g的目录夹
struts.objectFactory
The com.opensymphony.xwork2.ObjectFactory implementation class
com.opensymphony.xwork2.ObjectFactory接口QspringQ?br />
struts.objectFactory.spring.autoWire
Whether Spring should autoWire or not
是否自动l定Spring
struts.objectFactory.spring.useClassCache
Whether Spring should use its class cache or not
是否spring应该使用自n的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
是否strutsqo器中提供的静态内容应该被览器缓存在头部属性中
struts.serve.static
Whether the Struts filter should serve static content or not
是否strutsqo器应该提供静态内?br />
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中?nbsp;默认的includeParams
struts.velocity.configfile
The Velocity configuration file path
velocity配置文g路径
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接口?br />
struts.velocity.toolboxlocation
The location of the Velocity toolbox
velocity工具盒的位置
struts.xslt.nocache
Whether or not XSLT templates should not be cached
是否XSLT模版应该被缓?/p>
struts.custom.i18n.resources该属性指定Struts 2应用所需要的国际化资源文Ӟ如果有多份国际化资源文gQ则多个资源文g的文件名以英文逗号Q?Q隔开?/p>
struts.dispatcher.parametersWorkaround 对于某些Java EE服务器,不支持HttpServlet Request调用getParameterMap()Ҏ(gu)Q此时可以设|该属性gؓtrue来解册问题。该属性的默认值是false。对?WebLogic、Orion和OC4J服务器,通常应该讄该属性ؓtrue?/p>
Struts2OGNL上下文设|ؓStruts2中的ActionContext(内部使用的仍然是OgnlContext)Qƈ值栈设ؓOGNL的根对象?br />
我们知道QOGNL上下文中的根对象可以直接讉KQ不需要用Q何特D的“标记”Q而引用上下文中的其他对象则需要?#8220;#”来标记。由于值栈是上下文中的根对象,因此可以直接讉K。那么对于值栈中的对象该如何访问呢QStruts2提供了一个特D的OGNLPropertyAccessorQ它可以自动查找栈内的所有对?从栈到栈底)Q直接找C个具有你所查找的属性的对象。也是_对于值栈中的M对象都可以直接访问,而不需要?#8220;#”?br />
假设值栈中有两个对象Qstudent和employeeQ两个对象都有name属性,student有学号属性numberQ而employee有薪水属性salary。employee先入栈,student后入栈,位于栈顶Q那么对于表辑ּname,讉K的就是student的name属性,因ؓstudent对象位于栈顶Q表辑ּsalaryQ访问的是employee的salary属性。正如你所见,讉K值栈中的对象属性或Ҏ(gu)Q无L明对象,也不?#8220;#”Q就好像值栈中的对象都是OGNL上下文中的根对象一栗这是Struts2在OGNL基础上做出的改进?br />
Q、[N]语法
如上所qͼ如果惌讉Kemployee的name属性,应该如何写表辑ּ呢?我们可以使用[N].xxx(N是从0开始的整数)q样的语法来指定从哪一个位|开始向下查扑֯象的属性,表达式[1].name讉K的就是employee对象的name属性?br />
在用[N].xxx语法Ӟ要注意位|序L(fng)含义Q它q不是表C?#8220;获取栈中索引为N的对?#8221;Q而是截取从位|N开始的部分栈?br />
Q、top关键?br />
top用于获取栈顶的对象,l合[N].xxx语法Q我们就可以获取栈中L位置的对象?br />
如:[0].top,[1].top{?br />
Q、访问静态成?br />
除了使用标准的OGNL表达式访问静态字D和静态方法外QStruts2q允怽不指定完整的cdQ而是通过“vs”前缀来调用保存在栈中的静态字D和静态方法?br />
@vs@FOO_PROPERTY
@vs@someMethod()
@vs1@someMethod()
vs表示ValueStackQ如果只有vsQ那么将使用栈顶对象的类Q如果在vs后面跟上一个数字,那么用栈中指定位|处的对象类?br />
Q、值栈中的Action实例
Struts2框架L把Action实例攑֜栈顶。因为Action在值栈中,而值栈又是OGNL中的根,所以引用Action的属性可以省?#8220;#”标记Q这也是Z么我们在l果面中可以直接访问Action的属性的原因?br />
Q、Struts2中的命名对象
Struts2q提供了一些命名对象,q些对象没有保存在值栈中,而是保存在ActionContext中,因此讉Kq些对象需要?#8220;#”标记。这些命名对象都是Mapcd?br />
parameters
用于讉Kh参数。如Q?parameters['id']?parameters.idQ相当于调用了HttpServletRequest对象的getParameter()Ҏ(gu)?br />
注意Qparameters本质上是一个用HttpServletRequest对象中的h参数构造的Map对象Q一量对象被创徏(在调用Action实例之前已l创建好?Q它和HttpServletRequest对象没有了M关系?br />
request
用于讉Kh属性。如Q?request['user']?request.userQ相当于调用了HttpServletRequest对象的getAttribute()Ҏ(gu)?br />
session
用于讉Ksession属性。如Q?session['user']?session.userQ相当于调用了HttpSession对象的getAttribute()Ҏ(gu)?br />
application
用于讉Ka(chn)pplication属性。如Q?application['user']?application.userQ相当于调用了ServletContext的getAttribute()Ҏ(gu)?br />
attr
如果PageContext可用Q则讉KPageContextQ否则依ơ搜索request、session和application对象?
]]>
2.id属?可选属? 是指集合元素的id
3.status属?可选属?该属性在q代时会产生一个IteratorStatus对象,该对象可以判断当前元素的位置,包含了以下属性方?
int getCount(); q代元素个数
int getIndex(); q代元素当前索引
boolean getFirst(); 是否为第一?/p>
boolean getEven(); 是否为偶
boolean getLast(); 是否最后一?/p>
bolean getOdd(); 是否为奇
׃iteratorstatus对象q不是ognl的根对象因此讉K需要加?#讉K如下例子:
<s:iterator value=”{’dd’,'bb’,'cc’}” status=”st”>
<s:if test=”#st.odd”>
<s:property value=”#st.index”/>
</s:if>
</s:iterator>
此外:iterator也可以P代map对象,map对象中有几对key-value pP代几?分别使用
<s:property value=”key”/>
<s:property value=”value”/>
输出卛_.
查看struts.properties? {struts-core-2.06.jar}/org/apache/struts2/default.properties文gQ其中有如下配置Q?
struts.ui.theme=xhtml
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl
q一D就是关于struts2模版的配|信息,我们可以修改struts.properties文gQ将其改?
struts.ui.theme=simple
struts.ui.templateDir=template
struts.ui.templateSuffix=ftl
如果没有struts.properties文gQ可以修改struts.xml文gQ在其中加入如下?/span>
<constant name="struts.ui.theme" value="simple" />
<constant name="struts.ui.templateDir" value="template" />
<constant name="struts.ui.templateSuffix" value="ftl" />