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>