Tuesday, January 10, 2012

STRUTS 2 Interceptors

Interceptors in STRUTS 2

Many of the features provided in the Struts2 framework are implemented using interceptors; examples include exception handling, file uploading, lifecycle callbacks and validation. Interceptors are conceptually the same as servlet filters or the JDKs Proxy class. They provide a way to supply pre-processing and post-processing around the action. Similar to servlet filters,interceptors can be layered and ordered. They have access to the action being executed, as well as all environmental variables and execution 
properties. (Reference: Ian Roughley - Starting Struts 2 Book)

Below are the implementing interceptors mentioned:
  1. Spring Framework  the ActionAutowiringInterceptor interceptor.
  2. Request String and Form Values  the ParametersInterceptor interceptor.
  3. Servlet-based objects  the ServletConfigInterceptor interceptor.
The first two interceptors work independently, with no requirements from the action, but the last interceptor ServletConfigInterceptor is different.It works with the assistance of the following interfaces:
  • SessionAware to provide access to all the session attributes via a Map
  • ServletRequestAware to provide access to the HttpServletRequest object
  • RequestAware to provide access to all the request attributes via a Map
  • ApplicationAware to provide access to all the application attributes via a Map
  • ServletResponseAware to provide access to the HttpServletResponse object
  • ParameterAware to provide access to all the request string and form values attributes via a Map
  • PrincipalAware to provide access to the PrincipleProxy object; this object implements the principle and role methods of the HttpServletRequest object in implementation, but by providing a proxy,allows for implementation independence in the action
  • ServletContextAware to provide access to the ServletContext object

0 comments:

Blog Widget by LinkWithin

JS-Kit Comments

  © Blogger template Newspaper III by Ourblogtemplates.com 2008

Back to TOP