Search code examples
spring-mvcspring-3modelandview

Spring MVC, Return ModelAndView statements are ignored in Controller


I have following app setup.

  • The dispatcher servlet is matched to the *.htm URL pattern.
  • Controller has the annotation @RequestMapping(value = "doSuccess")
  • The method for the above annotation just returns new ModelAndView("success");

 <bean id="jspViewResolver"
      class="org.springframework.web.servlet.view.InternalResourceViewResolver"
      p:prefix="/WEB-INF/jsp/"
      p:suffix=".jsp" 
      p:order="1"/>

  • The index page has the link

<a href="doSuccess.htm">Click me</a>

  • There is a file called success.jsp located in /WEB-INF/jsp/

Now, when I click on the Click me, I get a 404. I did a bit of debugging and realized that the method in the controller was indeed being called but irrespective of the return statement it is trying to find doSuccess.htm.


Solution

  • I figured the error. I was using Netbeans and i used the auto complete imports. It was importing the org.springframework.web.portlet.ModelAndView instead of servlet.ModelAndView.