Child pages
  • Constant Configuration

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents

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, and so on. Second, they specify which Bean implementation, among multiple implementations of a given type, should be chosen.

...

In the web.xml file, any FilterDispatcher initialization parameters are loaded as constants.

Value substitution

Since Apache Struts 2.5.6 it is possible to use value substitution when defining constants in struts.xml file. You can also define a default value if given System property or ENV variable is missing, see example below:

Code Block
xml
xml
<struts>
    <constant name="os" value="Current OS = ${os.name}"/>


    <constant name="struts.devMode" value="${env.STRUTS_DEV_MODE:false}"/>
</struts>

Note: substitution is limited to System properties and ENV variables and works only for constants (as for now).

Sample usage

Code Block
XML
XML
titleConstant Example (struts.xml)

<struts>

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

  ... 

</struts>
Code Block
titleConstant Example (struts.properties)

struts.devMode = true
Code Block
XML
XML
titleConstant 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>