zoukankan      html  css  js  c++  java
  • 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>
    

      

  • 相关阅读:
    Angular Material Starter App
    缺少标识符、字符串或数字
    jquery ajax post 传递数组 ,多checkbox 取值
    Circular dependencies cannot exist in RelativeLayout
    第二次作业
    第一次作业
    第一次作业
    软工实践个人总结
    第01组 Beta版本演示
    第01组 Beta冲刺(4/5)
  • 原文地址:https://www.cnblogs.com/donleo123/p/11978400.html
Copyright © 2011-2022 走看看