SpringMVC configured interceptor (interceptors) have shown no solution css, js style

First, because the configuration of web.xml

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

  Cause all connections will go through DispatcherServlet, will filter out css, js and other styles, resulting in page can not be rendered success

It is necessary to release static resource configuration file in springmvc

<! - filter Static Resources ->
    <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/"/>

  

If you configure the interceptor, the interceptor released in the static resources

 <! - Configure interceptor ->
    <mvc:interceptors>
        <mvc:interceptor>
            <-! Intercepts all mvc controllers ->
            <mvc:mapping path="/**"/>
            <- mvc:! Exclude-mapping is another intercept, it can not be intercepted on a page in your later testing, so do not go
                The method of obtaining inside the preHandler LoginInterceptor not address the intercepted request uri (preferably) ->
            <! - The following resources are not to intercept ->
            <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>

  

 

Guess you like

Origin www.cnblogs.com/donleo123/p/11978400.html