Constants
provide a simple way to customize a Struts application by defining key
settings that modify framework and plugin behavior. There are two key
roles for constants. First, they are used to override settings like the
maximum file upload size or whether the Struts framework should be in
"devMode" or not. Second, they specify which Bean, among multiple implementations of a given type, should be chosen.
常量提供了简单的途径来定制一个Struts应用,它是定义关键设置来改变框架和插件的行为的。常量有两个关键作用,第一覆盖默认设置,例如限定上传文件的大小或者Struts框架是否因该是devMode。第二,定义在给定类型的多种实现方面,它们描述那种bean应该被选择。
Constants can be declared in multiple files. By default, constants
are searched for in the following order, allowing for subsequent files
to override previous ones:
- struts-default.xml
- struts-plugin.xml
- struts.xml
- struts.properties
- web.xml
The struts.properties file is provided for backward-compatiblity with WebWork.
In the various XML variants, the constant element has two required attributes: name and value.
Attribute |
Required |
Description |
name |
yes |
the name of the constant |
value |
*yes |
the value of the constant |
In the struts.properties file, each entry is treated as a constant.
In the web.xml file, any FilterDispatcher initialization parameters are loaded as constants.
Sample usage
<struts>
<constant name="struts.devMode" value="true" />
...
</struts>
<web-app id="WebApp_9" version="2.4"
xmlns="http:
xmlns:xsi="http:
xsi:schemaLocation="http:>
<filter>
<filter-name>struts</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
<init-param>
<param-name>struts.devMode</param-name>
<param-value>true</param-value>
</init-param>
</filter>
...
</web-app>