I have a controller in Spring MVC 3.2 which I want to allow the follow url's: http://localhost:8080/mypage http://localhost:8080/mypage/ http://localhost:8080/mypage/foo
I want to exclude anything else i.e. http://localhost:8080/mypage/bar should result in an error. Currently bar gets mapped to the getStuff method.
I assume I must be able to accomplish this without using a filter?
My servlet mapping looks like this:
<servlet-mapping>
<servlet-name>MyServlet</servlet-name>
<url-pattern>/mypage/*</url-pattern>
</servlet-mapping>
The controller request mapping:
@RequestMapping(method = RequestMethod.GET)
public String getView(HttpServletRequest request, @ModelAttribute("myform") final MyForm form) {
return "myview";
}
@ResponseBody
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
@POST
@RequestMapping(value = "/save")
public String onSave(@RequestBody MyForm form, HttpServletRequest request, HttpServletResponse response) {
return "saved";
}