Concept of Struts2.0 Interceptor

Concept of Struts2.0 Interceptor

Previous Home Next

 

The Struts2 framework provide a mechanism of controlling request data before invoking action class and after invoking action, they give service between the controller and action . Interceptors performs tasks such as Logging, Validation, File Upload, Double-submit guard etc.

 
The request processing lifecycle of Struts2 framework
  • User send the request on the server .
  • Server invoke the FilterDispatcher class.
  • All interceptor will be fired . Interceptors performs tasks such as Logging, Validation,File Upload,Double-submit guard etc.
  • Action is executed and the Result is generated by Action.
  • The output of Action is rendered in the view (JSP, Velocity, etc) and the result is returned to the user.
Example:-

<!DOCTYPE struts PUBLIC 
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<package name="demo">
<result-types>
<result-type name="dispatcher" class="org.apache.struts2.dispatcher.ServletDispatcherResult" default="true"/>
</result-types>
<interceptors>
<interceptor name="paramSetter" class="mypack.MyInterceptor"/>
</interceptors>
<action name="login" class="mypack.LoginAction">
<interceptor-ref name="paramSetter"/>
<result name="success">/hello.jsp</result>
<result name="failure">/relogin.jsp</result>
</action>
</package>
</struts>

Previous Home Next