Struts

Class ActionServlet in struts
adplus-dvertising
Previous Home Next

The class ActionServlet belongs to org.apache.struts.action.*; package, which work as a "controller" in the Model-View-Controller (MVC) design pattern for web applications that is commonly known as "Model 2" in struts framework. The main job of controller is:-

  • process all user requests
  • determine what the user is trying to achieve according to the request
  • pull data from the model (if necessary) to be given to the appropriate view, and
  • select the proper view to respond to the user.

For each request made of the controller, the method process (HttpServletRequest, HttpServletResponse) will be called. This method simply determines which module should service the request and then invokes that module's RequestProcessor's process method, passing the same request and response.

Architected of Model 2 application as follows:

  • "View" component is prime component of an MVC architecture because the user interface will generally be created with server pages, which shouldn't contain any business logic.
  • Forms and hyperlinks in the "View" component that require business logic to be executed will be submitted to a request URI that is mapped to this servlet. That servlet called ActionServlet and delegates the handling of a request to a RequestProcessor object. This component represents the "controller" component of an MVC architecture.
  • The RequestProcessor selects an Action class according to request to perform the requested business logic, or delegates the response to another resource. The Action class can call the JavaBeans to manipulate the state of the application's interaction with the user and store as session and request( depending upon application need ).Such JavaBeans represent the "Model" component of an MVC architecture. Instead of producing the next page of the user interface directly, Action classes generally return an ActionForward to indicate which resource should handle the response. If the Action does not return null, the RequestProcessor forwards or redirects to the specified resource (by utilizing RequestDispatcher.forward or Response.sendRedirect) so as to produce the next page of the user interface

Default mapping of ActionServlet in the web.xml file

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5">
<!--Default configuration and mapping
of Action class -->
<servlet>
	<!-- ActionServlet Mapping Name -->
<servlet-name>action</servlet-name>
<!-- ActionServlet package name -->
<servlet-class>org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
  <!-- default Struts configuration here -->
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<init-param>
<param-name>debug</param-name>
<param-value>2</param-value>
</init-param>
<init-param>
<param-name>detail</param-name>
<param-value>2</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>
	<!-- Action class mapping here-->
<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
	<!-- View file mapping -->
<welcome-file-list>
<welcome-file>login.jsp</welcome-file>
</welcome-file-list> 
</web-app>

Request Processor : It is designed as a drop-in replacement of the Struts 1.2.x behaviour and brings greater flexibility and easier customization to the request processing process. Request processor define some command classes which belong to either the org.apache.struts.chain.commands or org.apache.struts.chain.commands.servlet packages.

Previous Home Next