springmvc无法跳转到首页controller

来源:互联网 发布:手机屏幕跑出蜘蛛软件 编辑:程序博客网 时间:2024/06/14 22:25

1.默认tomcat容器的默认页面。 

/index.html 

这种方式适合访问静态的页面(也包括JSP)或者说是没有任何参数的页面。

2.spirng mvc 默认index controller 方式 
如果在tomcat容器没有配置默认页面,怎spring mvc 会主动去寻找/index的controller,如果有则会调用,没有则会显示404页面。 
@RequestMapping(value=”/index”) 
public ModelAndView index(HttpServletRequest request, HttpServletResponse response){ 
return new ModelAndView(“index”); 
}

3.spirng mvc 配置根节点访问“/”方式 
这种方法比较极端,就是配置一个名为“/”的controller,就是输入完网址之后就会调用。这种方法是前面两种方法都没有配置的时候。 
@RequestMapping(value=”/”) public ModelAndView index(HttpServletRequest request, HttpServletResponse response){ return new ModelAndView(“index”); }

三种方法的级别高低:1>>3>>2;因为tomcat的容器级别比spring要高,以上3钟配置都存在的情况,优先使用tomcat。因为配置了”/”的controller,所以会先匹配到相关的controller,而不会先寻找/index controller.

注意,即使web.xml没有添加,tomcat也会自动默认去寻找在webroot目录下面的index文件,如果要使用后面两种方法,则要保证webroot下面没有index相关的文件。

以上方法如果有错请各位指出,仅供学习用

我的情况是有个requestMapping为/的controller方法,还有个index.jsp页面,但是始终无法跳转到这个controller方法。后来将index.jsp修改为home.jsp并让controller的这个方法跳转到home页面。ok,问题就解决了。

请加入我的qq群:425783133

原创粉丝点击