Spring 3 mvc:resources导致mvc:interceptors多次运行 [英] Spring 3 mvc:resources causing mvc:interceptors to run multiple times
问题描述
在具有以下配置的Spring 3 MVC dispather-servlet.xml中,似乎每当一个名为.js的文件被拦截器启动时.
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/" />
我的view/jsp调用了四个.js,拦截器运行了四次...
My view/jsp calls four .js and the interceptor runs four times...
设置xml文件以免发生这种情况的正确方法是什么?
What is the proper way to set up the xml file so that this does not happen?
谢谢
推荐答案
实际上是浏览器在请求JS文件,因此正在向您的应用程序发出4个HTTP请求.您需要使用mvc:interceptor的"mapping"元素来选择拦截器将应用于的路径的子集.例如:
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
这篇关于Spring 3 mvc:resources导致mvc:interceptors多次运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!