众所周知,Tomcat的Default Servlet的servlet-mapping为
1 <servlet-mapping> 2 <servlet-name>default</servlet-name> 3 <url-pattern>/</url-pattern> 4 </servlet-mapping>如果在基于SpringMVC的项目中做如下设置:
DispatcherServlet的 url-pattern同样设置为 “/”,在web.xml中添加 1 <welcome-file-list> 2 <welcome-file>index.html</welcome-file> 3 <welcome-file>index.jsp</welcome-file> 4 </welcome-file-list>在后台代码中添加Controller,用于响应对应用根目录的访问,代码如下 @Controller public class HomeController { public HomeController() { } @RequestMapping(value = "/",method = RequestMethod.GET) public String home(){ return "home"; //home为/WEB-INF/views/home.jsp页面的逻辑名称 } @RequestMapping(value = "/test",method = RequestMethod.GET) public String test(){ return "home"; } }
如果访问应用的根路径,是返回index.html页面,还是进入HomeController 并返回 home.jsp?
转载于:https://www.cnblogs.com/canger/p/7875470.html