现在的位置: 首页 > 综合 > 正文

Struts2中的全局属性详解

2018年05月09日 ⁄ 综合 ⁄ 共 6002字 ⁄ 字号 评论关闭

1.Struts2的全局属性

我们在使用Struts2进行开发的时候,发现其比Struts1.x要简便得多,其中的部分缘由是Struts2已经帮我们定义了许多以前需要程序员自己去配置的属性,下面我们就来详细的了解这些属性,以及如何修改这些属性以符合具体开发的要求。

 

2.Struts2的全局属性文件的位置

我们在使用Struts2进行开发的时候,有五个jar包是必须的,分别是:

commons-logging.jar

freemarker.jar

ognl.jar

struts2-core.jar

xwork.jar

其中在struts-core.jar这个包的org.apache.struts2包下有个default.properties的属性文件这就是struts2的全局属性文件。

 

3.全局属性详解

 

#使用指定的Configuration来配置struts2,Configuration可以继承自org.apache.struts2.config.Configuration来构建用户自定义的struts的配置参数

struts.configuration=org.apache.struts2.config.DefaultConfiguration

 

# 设置缺省的地区代码

struts.locale=en_US

 

#设置Struts2国际化的字符编码

struts.i18n.encoding=UTF-8

 

# 设置对象工厂,如果指定的话,那么缺省的对象工厂将会被覆盖,注意:某些情况下,可以使用简化标记,例如“spring”,大多数情况下都必须指定com.opensymphony.xwork2.ObjectFactory类的子类的完整类名,

# 例如:struts.org.objectFactory = com.opensymphony.xwork2.StrutsObjectFactory

struts.objectFactory = spring

 

# 当使用SpringObjectFactory时,指定autoWiring逻辑,有效值是:name,type,auto和constructor,其中缺省值是name。

struts.objectFactory.spring.autoWire = name

 

# 指示struts-spring整合,如果类的实例需要被缓存,这是应当的,除非以后spring发行版使之成为可能

# 设为true吧,如果你不能确定你正在做什么的话,有效的值是:true,false。缺省为true

struts.objectFactory.spring.useClassCache = true


# 如果指定这个值的话,那么缺省的对象类型决定者将被覆盖,注意:某些情况下可以使用简单标记,例如“triger”或者“notiger”,通常应该指定com.opensymphony.xwork2.util.ObjectTypeDeterminer接口的实现类的完整类名。

# 另外缺省时,由com.opensymphony.xwork2.util.DefaultObjectTypeDeterminer来侦测类的类型。

# 使用泛型时,com.opensymphony.xwork2.util.GenericsObjectTypeDeterminer自xwork2后,已经不再推荐使用,它的功能已经被整合到了DefaultObjectTypeDeterminer。

# 如果要禁用tiger的支持,可以将值设为“notiger”。

struts.objectTypeDeterminer = tiger

 

# 配置处理http的post请求MIME-type为multipart/form-data的解析器,(文件上传时就使用这种)

# 默认使用jakarta,可选值为:cos,pell,jakarta。

struts.multipart.parser=jakarta

 

# 设置miltipart/form-data的数据临时存储目录,缺省为javax.servlet.context.tempdir

struts.multipart.saveDir= d:/develop/temp

 

# 设置miltipart/form-data类型数据的单个文件的最大值,缺省为2M。

struts.multipart.maxSize=2097152


# 加载自定义的属性文件,(不要覆盖struts.properties)

struts.custom.properties=application,org/apache/struts2/extension/custom

 

# 请求的URL与action间该怎么映射,缺省为org.apache.struts2.dispatcher.mapper.DefaultActionMapper

struts.mapper.class=org.apache.struts2.dispatcher.mapper.DefaultActionMapper


# 这个属性由DefaultActionMapper使用,你可以提供一个由逗号分隔的列表,来表示action的扩展名。

# 例如:struts.action.extension = do,action,aspx,缺省为action

struts.action.extension=action

 

# 由FilterDispatcher使用,如果为true,那么struts将从它的内部jar中提供静态内容的服务

# 如果为false,那么静态内容必须是<context_path>/struts才有效,缺省为true

struts.serve.static=true

 

# 由FilterDispatcher使用,只有在struts.serve.static=true的情况下,这个值才有效

# 如果为true,则struts将为静态内容输入报头,浏览器将缓存,

#
如果为false,则struts将为静态内容输入报头,浏览器不缓存,

# 缺省为true

struts.serve.static.browserCache=true

### Set this to false if you wish to disable implicit dynamic method invocation
### via the URL request. This includes URLs like foo!bar.action, as well as params
### like method:bar (but not action:foo).
### An alternative to implicit dynamic method invocation is to use wildcard
### mappings, such as <action name="*/*" method="{2}" class="actions.{1}">
struts.enable.DynamicMethodInvocation = true

### Set this to true if you wish to allow slashes in your action names.  If false,
### Actions names cannot have slashes, and will be accessible via any directory
### prefix.  This is the traditional behavior expected of WebWork applications.
### Setting to true is useful when you want to use wildcards and store values
### in the URL, to be extracted by wildcard patterns, such as
### <action name="*/*" method="{2}" class="actions.{1}"> to match "/foo/edit" or
### "/foo/save".
struts.enable.SlashesInActionNames = false

### use alternative syntax that requires %{} in most places
### to evaluate expressions for String attributes for tags
struts.tag.altSyntax=true

### when set to true, Struts will act much more friendly for developers. This
### includes:
### - struts.i18n.reload = true
### - struts.configuration.xml.reload = true
### - raising various debug or ignorable problems to errors
###   For example: normally a request to foo.action?someUnknownField=true should
###                be ignored (given that any value can come from the web and it
###                should not be trusted). However, during development, it may be
###                useful to know when these errors are happening and be told of
###                them right away.
struts.devMode = false

### when set to true, resource bundles will be reloaded on _every_ request.
### this is good during development, but should never be used in production
struts.i18n.reload=false

### Standard UI theme
### Change this to reflect which path should be used for JSP control tag templates by default
struts.ui.theme=xhtml
struts.ui.templateDir=template
#sets the default template type. Either ftl, vm, or jsp
struts.ui.templateSuffix=ftl

### Configuration reloading
### This will cause the configuration to reload struts.xml when it is changed
struts.configuration.xml.reload=false

### Location of velocity.properties file.  defaults to velocity.properties
struts.velocity.configfile = velocity.properties

### Comma separated list of VelocityContext classnames to chain to the StrutsVelocityContext
struts.velocity.contexts =

### Location of the velocity toolbox
struts.velocity.toolboxlocation=

### used to build URLs, such as the UrlTag
struts.url.http.port = 80
struts.url.https.port = 443
### possible values are: none, get or all
struts.url.includeParams = get

### Load custom default resource bundles
# struts.custom.i18n.resources=testmessages,testmessages2

### workaround for some app servers that don't handle HttpServletRequest.getParameterMap()
### often used for WebLogic, Orion, and OC4J
struts.dispatcher.parametersWorkaround = false

### configure the Freemarker Manager class to be used
### Allows user to plug-in customised Freemarker Manager if necessary
### MUST extends off org.apache.struts2.views.freemarker.FreemarkerManager
#struts.freemarker.manager.classname=org.apache.struts2.views.freemarker.FreemarkerManager

### Enables caching of FreeMarker templates
### Has the same effect as copying the templates under WEB_APP/templates
struts.freemarker.templatesCache=false

### See the StrutsBeanWrapper javadocs for more information
struts.freemarker.wrapper.altMap=true

### configure the XSLTResult class to use stylesheet caching.
### Set to true for developers and false for production.
struts.xslt.nocache=false

### A list of configuration files automatically loaded by Struts
struts.configuration.files=struts-default.xml,struts-plugin.xml,struts.xml

### Whether to always select the namespace to be everything before the last slash or not
struts.mapper.alwaysSelectFullNamespace=false

### END SNIPPET: complete_file

抱歉!评论已关闭.