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

<welcome-file-list> 

  <welcome-file>/index.html</welcome-file> 

</welcome-file-list>

这种方式适合访问静态的页面(也包括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相关的文件。


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



目前系统使用第二种:

第一步:

不能出现index.XXC

第二步:

在web.xml中不用<welcome-file-list>标签

加上:

 <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
 </servlet-mapping>

第三:在控制层的请求为:

@RequestMapping(value="/", method=RequestMethod.GET)


第四 使用springsecurity 记得拦截请求的问题