sprior,
In this post I will refer to springapp/war/WEB-INF/springapp-servlet.xml as defined in Developing a Spring Framework MVC application step-by-step
case 1:
Code:
public ModelAndView onSubmit(Object command) throws ServletException {
...
// increase logic
return new ModelAndView(new RedirectView(getSuccessView()));
}
getSuccessView() returns hello.htm as defined here:
Code:
<bean id="priceIncreaseForm" class="web.PriceIncreaseFormController">
<property name="sessionForm"><value>true</value></property>
<property name="commandName"><value>priceIncrease</value></property>
<property name="commandClass"><value>bus.PriceIncrease</value></property>
<property name="validator"><ref bean="priceIncreaseValidator"/></property>
<property name="formView"><value>priceincrease</value></property>
<property name="successView"><value>hello.htm</value></property>
<property name="productManager">
<ref bean="prodMan"/>
</property>
</bean>
hello.htm will then be wrapped into a RedirectView. This will result in a javax.servlet.http.HttpServletResponse.sendRedirec t to /hello.htm send to the Web Agent (IE, Mozialla, ...).
Spring DispatcherServlet will then handle the new HTTP /hello.htm request and call the corresponding controller (SpringappController):
Code:
<bean id="urlMapping" class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
<property name="mappings">
<props>
<prop key="/hello.htm">springappController</prop>
<prop key="/priceincrease.htm">priceIncreaseForm</prop>
</props>
</property>
</bean>
SpringappControler will return a new ModelAndView (hello):
Code:
public ModelAndView handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String now = (new java.util.Date()).toString();
logger.info("returning hello view with " + now);
Map myModel = new HashMap();
myModel.put("now", now);
myModel.put("products", getProductManager().getProducts());
return new ModelAndView("hello", "model", myModel);
}
Finally, the user will be redirected to /WEB-INF/jsp/hello.jsp as resolved by the viewResolver:
Code:
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass">
<value>org.springframework.web.servlet.view.JstlView</value>
</property>
<property name="prefix"><value>/WEB-INF/jsp/</value></property>
<property name="suffix"><value>.jsp</value></property>
</bean>
case 2:
Code:
protected void doSubmitAction(Object command) throws Exception {
...
// increase logic
// no need for the return of ModelAndView(...)
}
Since no ModelAndView is configured in doSubmitAction, null (default value for successView) will be used, but this is not a sendRedirect!!!.
hello.html (configured value for successView) will be resolved immediately by the viewResolver and the user will be redirected to /WEB-INF/jsp/hello.htm.jsp witch does not exist.
I hope this will help.