Spring MVC Configuration Concepts
In this section, we will review some core concepts related to configuring the Spring Web MVC Framework.
DispatcherServlet
DispatcherServlet (part of the org.springframework.web.servlet package) is the entry point to the world of Spring Web MVC, as depicted in Figure 7.2. It essentially dispatches requests to the controllers. If you have worked with Java web applications before, you will not be surprised to find out that this class is configured in the web.xml file, as shown in the following excerpt from the complete web.xml for Time Expression:
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
We will discuss DispatcherServlet in detail later in this chapter.
Handler Mappings
You can map handlers for incoming HTTP requests in the Spring application context file.These handlers are typically controllers that are mapped to partial or complete URLs of incoming requests.The handler mappings can also contain optional interceptors, which are invoked before and after the handler.This is a powerful concept. I will demonstrate an example of this later in this chapter when we use such a web interceptor for authentication and close our Hibernate session for the given HTTP request.
The following code excerpt taken from our complete timex-servlet.xml file shows how a handler can be mapped to a partial URL:
<bean id=”urlMap”
class=”org.springframework.web.servlet.handler.SimpleUrlHandlerMapping”>
<property name=”urlMap”>
<props>
<prop key=”/signin.htm”>signInController</prop>
<prop key=”/signout.htm”>signOutController</prop>
</props>
</property>
</bean>
View Resolvers
Spring uses the notion of view resolvers, which resolve view names to the actual views (enterhours to enterhours.jsp, for example).We will use Spring’s InternalResourceViewResolver class to resolve our view names. (This is covered in the next section.)
Anil Bist
Skills SpringMVC
Qualifications :- High School - SLV, College/University - Graphic Era Deemed Univ University,Location :-Dehradun,Dehradun,Uttarakhand,India
Description:-
I started my Professional Journey in 2006 with one of the Web Development Company in Bangalore and my 1st framework was "Ruby on Rail" as Web development and delivered around 5+ Projects using this platform. Then came another dimension as JEE/Sturst framework, Gradually I realized that I want to build something on my own and give my passion and energy on creating something different a
Explore