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>
    

      

  • 相关阅读:
    ActiveMQ 5.x 消息队列
    Spring Boot 整合 ElasticSearch 框架
    Spring Boot 整合 Logback 日志框架
    Spring Boot 整合定时任务和异步任务处理
    Spring 中使用 Java 5.0 Executor
    二级指针三种内存模型综合训练
    08-图8 How Long Does It Take (25 分)
    08-图9 关键活动 (30 分)
    08-图7 公路村村通 (30 分)
    C函数之index、strtoul
  • 原文地址:https://www.cnblogs.com/donleo123/p/11978400.html
Copyright © 2011-2022 走看看