View RSS Feed

Spring Framework

Spring MVC Basics

Rate this Entry
by , 11-27-2011 at 11:03 PM (1398 Views)
Spring MVC’s key component is the DispatcherServlet. This servlet that functions as Spring MVC’s front controller. Like any servlet, DispatcherServlet must be configured in the web application’s web.xml file. If you need to setup the Dispatcher Servlet it is relatively straightforward. Below is what needs to be added to the web.xml file.

Java Code:
       <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class>
Note that the <servlet-name> given to the servlet is important. This is because the DispatcherServlet loads the Spring application context after it has finished loading. The name of the xml file for the application context is taken from the <servlet-name>. The next thing to remember is to properly indicate the URLs that will be handled by the DispatcherServlet. Ones that you want to avoid are the following:
  • *.htm - implies a html form response,
  • /* - doesn’t imply any specific response
  • /app - is used to distinguish DispatcherServlet content from other content.

Instead it is recommended that you map to /. This is the default servlet responsible for handling all requests including for static content.

Submit "Spring MVC Basics" to Facebook Submit "Spring MVC Basics" to Digg Submit "Spring MVC Basics" to Submit "Spring MVC Basics" to StumbleUpon Submit "Spring MVC Basics" to Google

Tags: spring mvc Add / Edit Tags
MVC , Spring 3