Powered by Blogger.

How ActionServlet acting as a FrontController.in Struts

>> Sunday, June 14, 2009

A special web resource of web application that traps request comming to other web application to execute common and global pre request processing logic by username and password is called "Front Controller".

Servlet acting as a Front-controller , then it is called Front-controller servlet. If JSP is acting as Front-controller then it is called Front-controller JSP.
Action Servlet acting as Front Controller_JavabynataraJ
To make ordinary Servlet/Jsp as front controller you must be configured having directory match URL-pattern or extension match URL-pattern. In Struts based applications ActionServlet is takes as Front Controller.Due to this we can make Action class response going to browser directly with out having any trapping of response from ActionServlet. Since Action Servlet is controller of Struts based MVC application, it is recommended to write such logic in Action class based on which Action servlet traps the response of Action class.
  • Front controller web resource is responsible to trap request comming to other web resources of web application but it is not responsible to trap response generated by other web resources of web applicaion.
Q: Why ActionServlet is given as FrontController Servlet of Struts based web application..?

A: The class(not servlet,jsp) of web application can't take http request directly. Action classes of struts application are ordinary java classes . But they can't take http request given by browser directory. To overcome this problem front controller action Servlet traps all the requests cumming to struts based web application, and passes the request to appropriate action classes this is possible only when action servlet is front controller .

If the form generated request to struts based web-application always targets to executes business logic of Action class. Since Action class can't take this http request directly. Traping thes request and passing this request to Action class is the responsibility of Front Controller Actionservlet.
  • Even though ActionServlet is built-in-servelt configure in that serlet in web.xml as front controller eigther by having directory match or extension match url-pattern is the responsibility of programmer.
  • A Servlet becomes front controller when it is having extension match or directory match url-pattern and pre reqesition processing logic.
  • Action servlet can be configure by having directory match or extension match url-pattern one is recommended extension match url-pattern .That to" *. do" is recommended.
ActionServlet configuration code in web.xml

  • In the above code ActionServlet is configured as frontcontroller by having extension match url-pattern '*.do'.
  • In the above code "config" is the fixed unique parameter name expecting name & location of struts configuration file(technical input value). A .xml can become struts configuratio file. But this file name is location must be informed as to action servlet as the value of unique parameter "config" as shown above.
  • To pass non technical input values to servlet from browser as reduced use request parameter. (query string), form data. To pass technical value to servlet from server side useing web.xml.They take the support of unique parameters of context parameters.
  • To eqalize response time of all the requests comming to servlets make webcontainer creating object of servlet eigther during server startup or when web application is deployed. For this enable servlet.
  • To activate struts framework software before the first request it is recommended to enable.
Note: When multiple servlets of web application are enabled with in which order these servlets object should be created during server start-up will be decided based on their load-on-start-up priority values. High value indicates low priority,low value indicates high priority, zero indicates least priority.

Reference Books:

Related Posts Plugin for WordPress, Blogger...
© javabynataraj.blogspot.com from 2009 - 2014. All rights reserved.