Struts2 Configuration file and its roles
Struts 2 application is mainly dependent on two configuration files.
web.xml is common for all J2EE application and in case of Struts 2, it is used in the configuration of StrutsPrepareAndExecuteFilter, TilesListener etc.
When any request comes for struts web application, that request is first handled by web.xml file, where we do an entry for “StrutsPrepareAndExecuteFilter”, which dispatch a request object to appropriate action name.
StrutsPrepareAndExecuteFilter is having following responsibility :
1. Executing struts actions name
2. Cleaning up the ActionContext
3. Serving static content
4. Invoking interceptor chain for the request life-cycle
We are defining StrutsPrepareAndExecuteFilter entry in web.xml as:
Do read :
We don’t have to do an entry for taglib of struts in web.xml file because its already included into struts-core.jar file, so container automatically discover it .
The struts.xml file contains information about all the Action classes of application, configured interceptors for each Action class, Result for each Action execution. This file also describes the package structure of the application in which different modules are defined. Application specific constant like resource file, devMode, custom extension, theme settings also configured in this file. Below is the sample struts.xml file. All terms will be explained in their respective article.
** UPDATE: Struts 2 Complete tutorial now available here.
<constant name="struts.devMode" value="true" />
<package name="default" extends="struts-default">
<action name="welcome" class="com.action.LoginAction">