[英]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. 我正在使用Spring MVC实现一个网站,并且注意到以下问题。 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 我收到的视图user-panel.jsp不是解析器
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)
但是,当我将方法映射到@RequestMapping(value = "/user",method = RequestMethod.GET)
The view is resolved. 视图已解决。 The jsp page is placed at the root of the webapp (web directory ) jsp页面位于webapp的根目录(Web目录)
Now when I tried to map the method to @RequestMapping(value = "/user/panel",method = RequestMethod.GET)
and return new ModelAndView("/user-panel.jsp");
现在,当我尝试将方法映射到@RequestMapping(value = "/user/panel",method = RequestMethod.GET)
并return new ModelAndView("/user-panel.jsp");
NOTE THE ROOT SLASH. 注意根碎片。 The view resolved properly. 视图已正确解决。
You need to specify a view resolver in your configuration so spring knows where to look for the views. 您需要在配置中指定视图解析器,以便Spring知道在哪里查找视图。 If you do not provide one, you must specify the path to the file, which is why the "user-panel.jsp" does not work, but the "/user-panel.jsp" does work. 如果不提供,则必须指定文件的路径,这就是为什么“ user-panel.jsp”不起作用,而“ /user-panel.jsp”起作用的原因。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.