The core configuration file for the framework is the default (struts.xml
) file and should reside on the classpath of the webapp (generally /WEB-INF/classes
).
- The default file may include other configuration files as needed.
- A
struts-plugin.xml
file can be placed in a JAR and automatically plugged into an application, so that modules can be self-contained and automatically configured.- In the case of Freemarker and Velocity modules, the templates can also be loaded from the classpath, so the entire module can be plugged in as a single JAR.
FAQ
Can we break up a large struts.xml file into smaller pieces?
Next: struts.xml Examples
Example
...
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE xwork
PUBLIC
"-//OpenSymphony Group//XWork 1.0//EN"
"http://www.opensymphony.com/xwork/xwork-1.0.dtd">
<xwork>
<include file="webwork-default.xml"/>
<package name="default" extends="webwork-default">
<interceptors>
<interceptor-stack name="defaultComponentStack">
<interceptor-ref name="component"/>
<interceptor-ref name="defaultStack"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="defaultStack"/>
<action name="SimpleCounter" class="com.opensymphony.webwork.example.counter.SimpleCounter">
<result name="success" type="dispatcher">/success.jsp</result>
<interceptor-ref name="defaultComponentStack"/>
</action>
<!--
- Velocity implementation of the SimpleCounter. Also demonstrate a more verbose version of result element
-->
<action name="VelocityCounter" class="com.opensymphony.webwork.example.counter.SimpleCounter">
<result name="success" type="velocity">
<param name="location">/success.vm</param>
</result>
<interceptor-ref name="defaultComponentStack"/>
</action>
<!--
- Different method can be used (processForm).
-->
<action name="formTest" class="com.opensymphony.webwork.example.FormAction" method="processForm" >
<result name="success" type="dispatcher">/formSuccess.jsp</result>
<result name="invalid.token" type="dispatcher">/form.jsp</result>
<interceptor-ref name="defaultStack"/>
<interceptor-ref name="token"/>
</action>
</package>
</xwork>
...