Spring MVC3 默认页面(welcome-file)问题

来源:互联网 发布:sharpdesk软件 编辑:程序博客网 时间:2024/04/30 15:42
    <servlet><servlet-name>spring3mvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/conf/spring3mvc.xml</param-value></init-param><load-on-startup>1</load-on-startup> 
    </servlet>    <servlet-mapping>          <servlet-name>spring3mvc</servlet-name>          <url-pattern>/</url-pattern>      </servlet-mapping>

设置了/拦截后会对所有的进行过滤(静态资源可以在<mvc:resources/>上设置),但默认页面如http://localhost:8080/appnm 一般是会去welcome页面(welcome-file-list中配置),但也是被拦截,导致404页面找不到。

一种方法是配置一个Controller,其mapping是"",这样http://localhost:8080/appnm就会被该controller捕获到。

/** * 默认页 * @author wangzejie * */@Controller@RequestMapping("")public class IndexController {@RequestMapping("")public String index(HttpServletRequest request, HttpServletResponse response) throws IOException {return "index";}}


0 0
原创粉丝点击