Struts2框架的常量是对整个Struts2应用起做用的。在struts2-core-2.1.8.1.jar下的org.apache.struts2包下有一个default.properties文件,该文件为Struts2的全部常量都指定了默认值,下面咱们列出一些常见的:web
struts.i18n.encoding:指定web应用的默认编码集。该常量的默认值为UTF-8。该常量对于处理中文请求参数特别有用,咱们常将该常量设置为GBK或GB2312。spring
struts.objectFactory.spring.autoWire:apache
struts.multipart.parser:框架
struts.multipart.saveDir:eclipse
struts.multipart.maxSize:ui
struts.action.extension:编码
struts.enable.DynamicMethodInvocation:spa
struts.devMode:code
struts.i18n.reload:xml
struts.ui.theme:
struts.configuration.xml.reload:
struts.custom.i18n.resources:
struts.ognl.allowStaticMethodAccess:
还有不少,这里不一一列举。
Struts2配置常量总共有3种方式:
1. 经过struts.properties文件:放在类路径下,框架会自动加载,在myeclipse中也就是src目录下。这种方式主要是兼容webwork,不推荐使用。
2. 经过web.xml文件:为<filter>元素添加<init-param>子元素,在<init-param>中使用<param-name>和<param-value>子元素。这种方式也不推荐使用。
3. 经过struts.xml文件:放在类路径下便可。
Struts2框架按照以下顺序加载struts2常量:
1. struts-default.xml:
2. struts-plugin.xml:
3. struts.xml:
4. struts.properties:
5. web.xml:
为了不struts.xml文件过于庞大,提升struts.xml文件的可读性,咱们能够将一个struts.xml文件分解成多个配置文件,而后在struts.xml中包含其余配置文件:
<struts> <include file="struts-part.xml"/> ...... </struts>