Header Ads

ad

Front Controller in Spring MVC

What is Front Controller ?


>> A special web component of web application that acts as an entry point of web application having ability to apply common system services by trapping all or multiple requests and also delegates those requests to other components for processing is called Front Controller.

>> We can take either Servlet or JSP as Front Controller but Servlet is recommended.

>> In web application, we can take either one or more Front Controller but in maximum cases we take only 1 front controller.

>> We generally configure front controller servlet with extension match or directory match or "/*" url pattern

>> *.do, *.htm, *.youtechpoint, and etc..comes under extension match url pattern

>> x/y/* , x/*, youtechpoint/* comes under directory match url pattern.



Programmer deploys the Spring MVC web application in the server. Since <load-on-startup> is enabled on DispatcherServlet, pre-instantiation and initialization of DispatcherServlet takes place, in that process Servlet container performs following operations :


a) First it checks if there is any Listener class configured in web.xml if there is any it loads that class and creates the object of that class.

b) It creates ServletContext object.

c) Then it checks if there is any Filter class configured in web.xml or not, if it is there, Servlet container loads and create the object of that class.

d) Since <load-on-startup> is enabled on DispatcherServlet, servlet container loads, instantiate and initialize the DispatcherServlet, in this process init() method of DispatcherServlet is invoked.

e) Inside the init() method there is some logic to create IOC container of type ApplicationContext. It creates the IOC container of type ApplicationContext.

f) Then this IOC container creates the objects and perform the injection on spring bean classes that are in spring bean configuration file(xml) like Handler classes, View Resolver, HandlerMapping and etc..





No comments