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

故事扮演 提交于 2019-12-12 16:43:09

问题


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 the interceptor runs four times...

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

thanks


回答1:


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


来源:https://stackoverflow.com/questions/6298892/spring-3-mvcresources-causing-mvcinterceptors-to-run-multiple-times

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!