All the Request by the client are get processed by the ActionServlet only then get forwarded to the Request Processor.
ActionServlet is a single Servlet designed by the Apache using Front Controller Design Pattern. It follows the life cycle of the Servlet  by calling init() method then doPost() or doGet() and finally destroy().

Internal Implementation of the ActionServlet
  
public class ActionServlet extends HttpServlet {

   RequestProcessor rp = null;

   public void init(ServletConfig sc){

init() method is parameterized with ServletConfig object which is used to collect the data mentioned in the xml file under the init-param tag.

   String file_name= sc.getInitParameter("config");

Hence we hard-code the value " config " in the xml file because it is hard-coded in the ActionServlet class as well. And by this it will get the name of the struts-config xml file.

Start parsing or reading the data from the struts-config xml file by using the SAX Parser and store the information in the main memory.

    rp= new RequestProcessor(); 

}

After initializing the ServletConfig object RequestProcessor get initialized and store the data parsed from the struts-config file into the RequestProcessor object.

public void doPost(HttpServletRequest,HttpServletResponse) {

   rp.process(request,response);

}

or

public void doGet(HttpServletRequest,HttpServletResponse) {

   rp.process(request,response);

}

Then doPost() or doGet() method will be called by passing the request and response object and in this method a process() method will be called by the RequestProcessor object by passing HttpServletRequest and HttpServletResponse so that the request will be processed by the RequestProcessor object only.


public void destroy(){

   }
}

Finally destroy method will be called.

Note: Once the ActionServlet class is initialized then it will be eligible to handle any request with the url-pattern mentioned as *.do or any thing . 

This is the reason why we are writhing like *.do means any request will be handled by the ActionServlet only. This is also called as Front Controller Design Pattern that means a single Servlet is responsible to handle all the incoming request. 



0 comments:

Post a Comment

Ads 468x60px

.

Ads

.

Featured Posts

Popular Posts

Like Us On FaceBook

Total Pageviews

Online Members

Live Traffic