SpringMVC配置了拦截器(interceptors)却显示不出css、js样式的解决办法
首先因为在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>
相关推荐
zhangdy0 2020-05-31
HappyHeng 2020-05-16
whbing 2020-04-11
MicroBoy 2020-01-23
JudeJoo 2020-08-21
meleto 2020-08-15
玫瑰小妖 2020-07-18
dlutbob 2020-07-04
zmysna 2020-07-04
小鱿鱼 2020-06-26
MicroBoy 2020-06-17
zhongliwen 2020-06-13
zhongliwen 2020-06-13
qingjiuquan 2020-06-07
牧场SZShepherd 2020-06-03
spring艳 2020-05-30
方志朋 2020-05-30
咻pur慢 2020-05-27