不明白1:SpringMVC的默认页面

433 阅读1分钟

index.jsp

在webapp下创建index.jsp,与WEB-INF同级,输入网站默认访问此页面。

index.html

开启<mvc:default-servlet-handler/>,此时默认访问index.html(若无index.html则访问index.jsp) 这是因为tomcat中有web.xml配置了默认的欢迎页匹配。

```<welcome-file-list>
        <welcome-file>index.html</welcome-file>
        <welcome-file>index.htm</welcome-file>
        <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

<mvc:default-servlet-handler/>作用如下。

这允许将 DispatcherServlet Map 到“ /”(从而覆盖了容器默认 Servlet 的 Map),同时仍允许容器默认 Servlet 处理静态资源请求。它将 DefaultServletHttpRequestHandler 配置为具有 “/**”的 URLMap,并且相对于其他 URLMap 具有最低的优先级。该处理程序会将所有请求转发到默认 Servlet。因此,重要的是,它应以所有其他 URL HandlerMappings 的 Sequences 保留在最后。如果您使用 mvc:annotation-driven ,或者您要设置自己的自定义 HandlerMapping 实例,情况一定会如此,请确保将其 order 属性设置为 小于 DefaultServletHttpRequestHandler 的值 Integer.MAX_VALUE 。