web.xml 配置
<servlet> <servlet-name>SpringMVC</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <init-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:spring-mvc.xml</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>SpringMVC</servlet-name> <url-pattern>/</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>SpringMVC</servlet-name> <url-pattern>/index</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index</welcome-file> </welcome-file-list>
后台请求Controller
@RequestMapping("/index") public String index(HttpServletRequest request) { return "web/index"; }
这样的话用工程名直接访问,就可以路由 到/index .