常量的默认配置在struts2-core-2.1.8.1/org/apache/struts2/default.properties文件里,像定义访问action的默认扩展名、开发模式设置、i18n以及默认字符编码等等,例如struts.action.extension=action,,。
应当注意的是,一般情况不要修改框架系统的原始文件,如果要更改默认的配置项,可以采用覆盖的方式。struts.xml是struts2的基本配置文件之一。该文件内可以配置多个常量,以覆盖默认的常量配置,例如
常量可以在下面多个文件中进行定义,struts2加载常量的搜索顺序如下,后面的设置可以覆盖前面的设置:
default.properties文件
struts-default.xml
struts-plugin.xml
struts.xml
struts.properties(为了与webwork向后兼容而提供)
web.xml
下面列举几个常用的常量
### This can be used to set your default locale and encoding scheme
# struts.locale=en_US
struts.i18n.encoding=UTF-8//指定默认编码
### This can be used to set your default locale and encoding scheme
# struts.locale=en_US
struts.i18n.encoding=UTF-8//指定默认编码
# uses javax.servlet.context.tempdir by default
struts.multipart.saveDir=
struts.multipart.maxSize=2097152//上传文件大小限制
# uses javax.servlet.context.tempdir by default
struts.multipart.saveDir=
struts.multipart.maxSize=2097152//上传文件大小限制
### Used by the DefaultActionMapper
### You may provide a comma separated list, e.g. struts.action.extension=action,jnlp,do
### The blank extension allows you to match directory listings as well as pure action names
### without interfering with static resources.
struts.action.extension=action,,//指定处理请求的后缀
### Used by the DefaultActionMapper
### You may provide a comma separated list, e.g. struts.action.extension=action,jnlp,do
### The blank extension allows you to match directory listings as well as pure action names
### without interfering with static resources.
struts.action.extension=action,,//指定处理请求的后缀
### Used by FilterDispatcher
### This is good for development where one wants changes to the static content be
### fetch on each request.
### NOTE: This will only have effect if struts.serve.static=true
### If true -> Struts will write out header for static contents such that they will
### be cached by web browsers (using Date, Cache-Content, Pragma, Expires)
### headers).
### If false -> Struts will write out header for static contents such that they are
### NOT to be cached by web browser (using Cache-Content, Pragma, Expires
### headers)
struts.serve.static.browserCache=true// www.2cto.com 指定是否缓存静态资源,开发的时候最好关闭
### Used by FilterDispatcher
### This is good for development where one wants changes to the static content be
### fetch on each request.
### NOTE: This will only have effect if struts.serve.static=true
### If true -> Struts will write out header for static contents such that they will
### be cached by web browsers (using Date, Cache-Content, Pragma, Expires)
### headers).
### If false -> Struts will write out header for static contents such that they are
### NOT to be cached by web browser (using Cache-Content, Pragma, Expires
### headers)
struts.serve.static.browserCache=true//指定是否缓存静态资源,开发的时候最好关闭
### when set to true, Struts will act much more friendly for developers. This
### includes:
### - struts.i18n.reload = true
### - struts.configurat