Apache Struts 2 Documentation > Home > Guides > Core Developers Guide > Struts Configuration Elements > Constant Configuration |

Apache Struts 2 Documentation
Constant Configuration
Edit Page Browse Space Add Page Add News
Added by Don Brown, last edited by Ted Husted on Nov 20, 2006 (view change)

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.

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:

1. struts-default.xml
2. struts-plugin.xml
3. struts.xml
4. struts.properties
5. web.xml

The `struts.properties` file is provided for backward-compatiblity with WebWork.

## Constant

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

Constant Example (struts.xml)

    <struts>

      <constant name="struts.devMode" value="true" />

      ...

    </struts>

Constant Example (struts.properties)

    struts.devMode = true

Constant Example (web.xml)

    <web-app id="WebApp_9" version="2.4"
    	xmlns="http://java.sun.com/xml/ns/j2ee"
    	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    	xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

        <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>