Tuesday, December 31, 2013

Another way to get around the Spring MVC 404 exception

A lot of applications are set up without a default for displaying a home page - even if they have one. This (excellent) tutorial is a case in point:

http://codetutr.com/2013/04/09/spring-mvc-easy-rest-based-json-services-with-responsebody/

I managed to get it running in eclipse, but of course I got the page not found, 404 exception. With my recent research, however, I didn't feel quite as helpless as I usually do when faced with this. After checking out my last post, I realized what was lacking in this application was a default request mapping - i.e.


@RequestMapping({"/","/home"})

Since it came with a "home.jsp" already, I just copied a method from the STS-generated springMVC app:

public String home(Locale locale, Model model) {

      return "home";

}

If there wasn't a home.jsp there already, I could have copied one into WEB-INF/views from the generated project. 

Here's the page:



No comments:

Post a Comment