Spring's web MVC framework is, like many other web MVC frameworks, request-driven, designed around a central servlet that dispatches requests to controllers and offers other functionality that facilitates the development of web applications. Spring's Dispatcher Servlet however, does more than just that. It is completely integrated with the Spring IoC container and as such allows you to use every other feature that Spring has.
The request processing work flow of the Spring Web MVC Dispatcher Servlet is illustrated in the following diagram. The pattern-savvy reader will recognize that the Dispatcher Servlet is an expression of the “Front Controller” design pattern (this is a pattern that Spring Web MVC shares with many other leading web frame works).
The requesting processing workflow in Spring Web MVC (high level) The Dispatcher Servlet is an actual Servlet (it inherits from the Http Servlet base class), and as such is declared in the web.xml of your web application. You need to map requests that you want the Dispatcher Servlet to handle, by using a URL mapping in the same web.xml file.This is standard J2EE servlet configuration; the following example shows such a Dispatcher Servlet declaration and mapping:<web-app>
In the preceding example, all requests ending with .form will be handled by the example Dispatcher Servlet.This is only the first step in setting up Spring Web MVC. You now need to configure the various beans used by the Spring Web MVC frame work (over and above the Dispatcher Servlet itself).
In the Web MVC frame work, each Dispatcher Servlet has its own Web Application Context, which inherits all the beans already defined in the root Web Application Context. These inherited beans can be overridden in the servlet-specific scope, and you can define new scope-specific beans local to a given servlet instance.
Context hierarchy in Spring Web MVC:-
Upon initialization of a DispatcherServlet, the frame work looks for a file named [servlet-name]-servlet.xml in the WEB-INF directory of your web application and creates the beans defined there, overriding the definitions of any beans defined with the same name in the global scope.
Consider the following DispatcherServlet servlet configuration (in the web.xml file):<web-app>
With the above servlet configuration in place, you will need to have a file called /WEB-INF/golfing-servlet.xml in your application; this file will contain all of your Spring Web MVC-specific components (beans). You can change the exact location of this configuration file through a servlet initialization parameter.
The Web Application Context is an extension of the plain Application Context that has some extra features necessary for web applications.It differs from a normal Application Context in that it is capable of resolving themes, and that it knows which servlet it is associated with (by having a link to the Servlet Context).The Web Application Context is bound in the ServletContext, and by using static methods on the RequestContextUtils class you can always look up the Web Application Context if you need access to it.
The Spring Dispatcher Servlet uses special beans to process requests and render the appropriate views. These beans are part of Spring Frame work. You can configure them in the Web Application Context, just as you configure any other bean. However, for most beans, sensible defaults are provided so you initially do not need to configure them. These beans are described in the following table.
Table: Special beans in the WebApplicationContext
After you set up a DispatcherServlet, and a request comes in for that specific DispatcherServlet, the DispatcherServlet starts processing the request as follows:
Handler exception resolvers that are declared in the WebA pplication Context pick up exceptions that are thrown during processing of the request.Using these exception resolvers allows you to define custom behaviors to address exceptions.
The Spring Dis patcher Servlet also supports the return of the last-modification-date, as specified by the Servlet API. The process of determining the last modification date for a specific request is straight forward:the Dispatcher Servlet looks up an appropriate handler mapping and tests whether the handler that is found implements the Last Modified interface. If so, the value of the long get Last Modified(request) method of the Last Modified interface is returned to the client.
You can customize individual Dispatcher Servlet instances by adding servlet initialization parameters (init-param elements) to the servlet declaration in the web.xml file. See the following table for the list of supported parameters.
Table DispatcherServlet initialization parameters
Java-Springs Related Interview Questions
|Adv Java Interview Questions||J2EE Interview Questions|
|Core Java Interview Questions||JSP Interview Questions|
|Java-Springs Interview Questions||Java Servlets Interview Questions|
|JMS(Java Message Service) Interview Questions||Hibernate Interview Questions|
|Java applet Interview Questions||Java Interview Questions|
|Framework7 Interview Questions||Java collections framework Interview Questions|
|Java 8 Interview Questions||Java Programmer Interview Questions|
Introduction To Spring Framework
New Features And Enhancements In Spring 3.0
The Ioc Container
Validation, Data Binding, And Type Conversion
Spring Expression Language (spel)
Aspect Oriented Programming With Spring
Spring Aop Apis
Data Access With Jdbc
Object Relational Mapping (orm) Data Access
Marshalling Xml Using O/x Mappers
Web Mvc Framework
Integrating With Other Web Frameworks
Portlet Mvc Framework
Remoting And Web Services Using Spring
Enterprise Javabeans (ejb) Integration
Jms (java Message Service)
Task Execution And Scheduling
Dynamic Language Support
All rights reserved © 2018 Wisdom IT Services India Pvt. Ltd
Wisdomjobs.com is one of the best job search sites in India.