View RSS Feed

Spring Framework

Spring MVC Basics

Rate this Entry
by , 11-27-2011 at 10:03 PM (1298 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> 
     <servlet-name>springexamples</servlet-name> 
       <servlet-class>org.springframework.web.servlet.DispatcherServlet </servlet-class>
     <load-on-startup>1</load-on-startup> 
</servlet>
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 del.icio.us Submit "Spring MVC Basics" to StumbleUpon Submit "Spring MVC Basics" to Google

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

Comments