- Strusts allowed to create custom control by creating the subclass of ActionServlet class, but it's is not much usefull. Action Servlet deligate most of it's duties to RequestProcesser. RequestProcesser act as delegate and allowed to override process methods. We can create our own request processer & configured in struts-config file. This is used while adding plug-in's.
- Struts allows to add new functionality by using the Plug-in's (This is used commonly). Ex - Validation framework & tiles framework
- Struts supports multiple configuration files.
In Struts 1.1-1.2.x RequestProcessor contains the processing logic that the Struts controller servlet performs as it receives each servlet request from the container. You can customize the request processing behavior by subclassing this class and overriding the method(s) whose behavior you are interested in changing.
Therefore a new new request processor can be plugged in without touching the Servlet. (Users did not like to subclass ActionServlet.) RequestProcessor also made possible to use a different request processor for each module, if needed.
What design patterns are used in Struts?
Struts is based on model 2 MVC (Model-View-Controller) architecture. Struts controller uses the command design pattern and the action classes use the adapter design pattern. The
process()
method of the RequestProcessor uses the template method design pattern. Struts also implement the following J2EE design patterns. - Service to Worker
- Dispatcher View
- Composite View (Struts Tiles)
- Front Controller
- View Helper
- Synchronizer Token
What is the life cycle of ActionForm?
The lifecycle of
ActionForm
invoked by the RequestProcessor
is as follows:- Retrieve or Create Form Bean associated with
Action
- "Store" FormBean in appropriate scope (
request
orsession
) - Reset the properties of the FormBean
- Populate the properties of the FormBean
- Validate the properties of the FormBean
- Pass FormBean to
Action
1. call the saveToken() method in ActionClass which populate the form data
saveToken(request);
2. add the below in in action class assocated with saving the form data
if (isTokenValid(request) )
{ saveToken(request); }
Handling the Session time expires, navigate to expiry page.
Below code to be added in the jsp page.
<META HTTP-EQUIV="Refresh"
CONTENT="<%=session.getMaxInactiveInterval()%>;URL=logout.do?sessionTimeout=true">
Struts interview Questions - Click Here
<META HTTP-EQUIV="Refresh"
CONTENT="<%=session.getMaxInactiveInterval()%>;URL=logout.do?sessionTimeout=true">