开发者

Spring 3 mvc:resources causing mvc:interceptors to run multiple times

开发者 https://www.devze.com 2023-03-12 08:03 出处:网络
in Spring 3 MVC dispather-servlet.xml with the configuration below, it seems like everytime a .js file is called the interceptor is kicked off.

in Spring 3 MVC dispather-servlet.xml with the configuration below, it seems like everytime a .js file is called the interceptor is kicked off.

<mvc:interceptors>
    <bean class="com.something.SomeInterceptor" />
    </mvc:interceptors>

    <mvc:resources mapping="/js/**" location="/js/" />
    <mvc:resources mapping="/jsp/**" location="/jsp/" />

My view/jsp calls four .js and th开发者_如何学Ce interceptor runs four times...

What is the proper way to set up the xml file so that this does not happen?

thanks


It's actually the browser that is requesting the JS files, so 4 HTTP requests are being made to your application. You'll need to use the "mapping" element of mvc:interceptor to select a subset of paths that the interceptor will be applied to. For example:

<mvc:interceptors>
  <mvc:interceptor>
    <mapping path="/secure/*"/>
    <bean class="org.example.SecurityInterceptor" />
  </mvc:interceptor>
</mvc:interceptors
0

精彩评论

暂无评论...
验证码 换一张
取 消