mardi 7 avril 2015

Why does spring resolve views only when one level url path present on controller request mapping annotation

I am implementing a website with Spring MVC and I've noticed the following problem. I have a controller like this one



/**
* Created by adelin.ghanayem@cayetanogaming.com on 4/7/15.
*/
@Controller
@RequestMapping(value = "/")
public class UserControlPanelController {

// this url has a second level. /user/panel
@RequestMapping(value = "/user/panel",method = RequestMethod.GET)
@Secured(value = {"ROLE_USER"})
public ModelAndView mainPage(){
return new ModelAndView("user-panel.jsp");
}
}


The view user-panel.jsp is not resolver I receive



HTTP ERROR 404

Problem accessing /myapp/user/login-user.jsp. Reason:

/myapp/user/login-user.jsp


However, when I map the method to @RequestMapping(value = "/user",method = RequestMethod.GET)


The view is resolved. The jsp page is placed at the root of the webapp (web directory )


Now when I tried to map the method to @RequestMapping(value = "/user/panel",method = RequestMethod.GET) and return new ModelAndView("/user-panel.jsp"); NOTE THE ROOT SLASH. The view resolved properly.


Aucun commentaire:

Enregistrer un commentaire