首先因为在web.xml里面配置了

<filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  导致所有的连接都会经过DispatcherServlet,会过滤掉css、js等样式,导致页面无法渲染成功

因此需要在springmvc配置文件中放行静态资源

1  <!--过滤静态资源-->
2     <mvc:resources mapping="/common/**" location="/common/"/>
3     <mvc:resources mapping="/css/**" location="/css/"/>
4     <mvc:resources mapping="/images/**" location="/images/"/>
5     <mvc:resources mapping="/js/**" location="/js/"/>
6     <mvc:resources mapping="/json/**" location="/json/"/>
7     <mvc:resources mapping="/jsplug/**" location="/jsplug/"/>

如果配置了拦截器,在拦截器中放行静态资源

 1 <!--配置拦截器-->
 2     <mvc:interceptors>
 3         <mvc:interceptor>
 4             <!-- 拦截所有mvc控制器 -->
 5             <mvc:mapping path="/**"/>
 6             <!-- mvc:exclude-mapping是另外一种拦截,它可以在你后来的测试中对某个页面进行不拦截,这样就不用在
 7                 LoginInterceptor的preHandler方法里面获取不拦截的请求uri地址了(优选) -->
 8             <!--以下资源不进行拦截-->
 9             <mvc:exclude-mapping path="/user/toLogin" />
10             <mvc:exclude-mapping path="/user/login" />
11             <mvc:exclude-mapping path="/common/**"/>
12             <mvc:exclude-mapping path="/css/**"/>
13             <mvc:exclude-mapping path="/images/**"/>
14             <mvc:exclude-mapping path="/js/**"/>
15             <mvc:exclude-mapping path="/json/**"/>
16             <mvc:exclude-mapping path="/jsplug/**"/>
17             <bean class="com.ld.fyds.interceptor.LoginInterceptor"></bean>
18         </mvc:interceptor>
19     </mvc:interceptors>

 

版权声明:本文为donleo123原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/donleo123/p/11978400.html