web.xml
Deployment Descriptor file of the web applicationXML
File or Controller Layer Resourcesorg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
is the Front Controller class in Struts2 and every request processing starts from this class. Earlier versions of Struts2 uses org.apache.struts2.dispatcher.FilterDispatcher
as Front Controller class. <action name="*welcome" class="example.action.mapping.LinkAction" method="execute">
<result name="success">/welcome.jsp</result>
<result name="error">/error.jsp</result>
</action>
DispatchAction
.execute()
method of an Action class.execute()
method.struts-config.xml
Public ActionErrors Validate (ActionMapping mapping, HttpServletRequest request)
public void reset ((ActionMapping mapping, HttpServletRequest request)
struts-config.xml
), forwarding options are defined under action-mapping tag. test.do
, request will be forwarded to /pages/testing.jsp
using following configurations from struts-config.xml
file :<action path="/test" forward="/pages/testing.jsp">
<html:link</strong> page="/test.do</strong>">Controller Example</html:link>
<plug-in className="org.apache.struts.tiles.TilesPlugin" >
<set-property property="definitions-config" value="/WEB-INF/tiles-defs.xml" />
<set-property property="moduleAware" value="true" />
</plug-in>
com.opensymphony.xwork2.interceptor.ParametersInterceptor
interceptor is responsible for mapping request parameters to the Action class java bean properties. This interceptor is configured in struts-default package with name “params”. This interceptor is part of basicStack and defaultStack interceptors stack. init(), destroy() and intercept()
. init and destroy are the life cycle methods of an interceptor. Interceptors are Singleton classes and Struts2 initialize a new thread to handle each request. init()
method is called when interceptor instance is created and we can initialize any resources in this method. destroy()
method is called when application is shutting down and we can release any resources in this method. <constant name="struts.action.extension" value="action,do"></constant>
struts.convention.result.path
constant value in Struts2 configuration file to change the result pages location.<package name="user" namespace="/" extends="struts-default">
<global-results>
<result name="exception">/exception.jsp</result>
<result name="runtime_exception">/runtime_exception.jsp</result>
<result name="error">/error.jsp</result>
</global-results>
<global-exception-mappings>
<exception-mapping exception="java.lang.Exception" result="exception"></exception-mapping>
<exception-mapping exception="java.lang.Error" result="error"></exception-mapping>
<exception-mapping exception="java.lang.RuntimeException" result="runtime_exception"></exception-mapping>
</global-exception-mappings>
<action name="myaction" class="com.journaldev.struts2.exception.MyAction">
</action>
<action name="myspecialaction" class="com.journaldev.struts2.exception.MySpecialAction">
<exception-mapping exception="java.io.IOException" result="login"></exception-mapping>
<result name="login">/error.jsp</result>
</action>
</package>​
Struts.xml
file is one the major configuration records of Struts system which is utilized to characterize mapping between URL and action. At the point when the controller receives a client’s demand, the controller utilizes mapping data from this file to choose appropriate action class.