Request life cycle of Spring web applications

This post will analyse the request life cycle of Spring web applications with the codes of Spring Framework MVC application I did in lab.

1. Browser sends request, received by DispatcherServlet.

DispatcherServlet is set in war/WEB-INF/web.xml.



All the reqests as the name of *.htm will be handled by springapp, which is a DispatcherServlet.

2. To figure which controller to use.

<bean id=”urlMapping”>
<property name=”mappings”>
<prop key=”/hello.htm”>springappController</prop>
<prop key=”/priceincrease.htm”>priceIncreaseForm</prop>

This codes in war/WEB-INF/springapp-servlet.xml is mapping /hello.htm and /priceincrease.htm to 2 controllers separately.

3. Dispatcher server requests Controller, controller returns ModelAndView object.

In src/web/

public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

String now = (new java.util.Date()).toString();“returning hello view with ” + now);

Map myModel = new HashMap();
myModel.put(“now”, now);
myModel.put(“products”, getProductManager().getProducts());

return new ModelAndView(“hello”, “model”, myModel);

The controller returns a ModelAndView object whose viewName is “hello”, modelName is “model” and model object is a Map object named as myModel.

4. If ModelAndView contains logical name for a View, DispatcherServlet queries ViewResolver for the View object that will render the response.

<bean id=”viewResolver”>
<property name=”viewClass”>
<property name=”prefix”><value>/WEB-INF/jsp/</value></property>
<property name=”suffix”><value>.jsp</value></property>

This codes will add prfix and suffix to the viewName of ModelAndView object, in this example, hello will be fixed as /WEB-INF/jsp/hello.jsp .

5. DispatcherServlet requests the View Object. /WEB-INF/jsp/hello.jsp will be shown on browser.


About Sanju
I am Software Programmer. I am working in JAVA/J2EE Technologies.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: