方志朋 2019-12-03
首先因为在web.xml里面配置了
<filter-mapping> <filter-name>characterEncodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
导致所有的连接都会经过DispatcherServlet,会过滤掉css、js等样式,导致页面无法渲染成功
因此需要在springmvc配置文件中放行静态资源
<!--过滤静态资源--> <mvc:resources mapping="/common/**" location="/common/"/> <mvc:resources mapping="/css/**" location="/css/"/> <mvc:resources mapping="/images/**" location="/images/"/> <mvc:resources mapping="/js/**" location="/js/"/> <mvc:resources mapping="/json/**" location="/json/"/> <mvc:resources mapping="/jsplug/**" location="/jsplug/"/>
如果配置了拦截器,在拦截器中放行静态资源
<!--配置拦截器--> <mvc:interceptors> <mvc:interceptor> <!-- 拦截所有mvc控制器 --> <mvc:mapping path="/**"/> <!-- mvc:exclude-mapping是另外一种拦截,它可以在你后来的测试中对某个页面进行不拦截,这样就不用在 LoginInterceptor的preHandler方法里面获取不拦截的请求uri地址了(优选) --> <!--以下资源不进行拦截--> <mvc:exclude-mapping path="/user/toLogin" /> <mvc:exclude-mapping path="/user/login" /> <mvc:exclude-mapping path="/common/**"/> <mvc:exclude-mapping path="/css/**"/> <mvc:exclude-mapping path="/images/**"/> <mvc:exclude-mapping path="/js/**"/> <mvc:exclude-mapping path="/json/**"/> <mvc:exclude-mapping path="/jsplug/**"/> <bean class="com.lintrondata.fyds.interceptor.LoginInterceptor"></bean> </mvc:interceptor> </mvc:interceptors>