Configuring DispatcherServlet as the Front Controller

In a Java-based web application, all servlets are defined in the web.xml file. It is loaded in a web container at the bootstrap, and maps each servlet to a particular URL pattern. Similarly, the org.springframework.web.servlet.DispatcherServlet is the centerpiece of the Spring MVC; it needs to be configured in the same file--web.xml, and it is loaded at the bootstrap of the web application. At the time of bootstrapping, DispatcherServlet is invoked to create Spring's org.springframework.web.context.WebApplicationContext by loading the beans' configuration through Java, XML, or annotation-based. The servlet tries to fetch all the required components from this web application context. It has the responsibility to route the request through all the other components.

WebApplicationContext is a web version of the ApplicationContext, as discussed in previous chapters of this book. It has some additional capabilities necessary for web applications other than the ApplicationContext, such as servlet-specific scope request, session, and so on. The WebApplicationContext is bound in the ServletContext; you can also access it by using the static method of the RequestContextUtils class. Let's see the following code snippet for this:
ApplicationContext webApplicationContext = RequestContextUtils.findWebApplicationContext(request);
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset