Spring MVC Basics
by, 11-27-2011 at 11:03 PM (1363 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.
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: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>
- *.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.