First, a bit of context:
web.xml:
I match all /app/* requests to my dispatcher:
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>2</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/app/*</url-pattern>
</servlet-mapping>
My question, why does calling /app/import/view work when returning String:
Controller:
public class ImportController extends MultiActionController {
public String view(HttpServletRequest request, HttpServletResponse response) throws Exception
return "importer.home";
}
but NOT when returning ModelAndView:
public class ImportController extends MultiActionController {
public ModelAndView view(HttpServletRequest request, HttpServletResponse response) throws Exception {
ModelAndView mav = new ModelAndView("importer.home");
mav.addObject(new ExlFile());
return mav;
}
Is there a different naming convention if we use ModelAndView?
You’re using
MultiActionController, which has very strict constraints on method naming conventions and signatures.However, you shouldn’t be using
MultiActionControllerat all, it’s obsolete and deprecated. Write controllers as described in the Spring manual, i.e. using@Controllerand@RequestMapping, then you get much more flexible method signatures.