在Spring MVC 3.2.8中配置Servlet Context中的拦截器

时间:2016-05-19 08:35:31

标签: spring-mvc

我想在Web应用程序开发中面对浏览器后退按钮问题,所以我将其添加到我的servlet-context.xml

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xsi:schemaLocation="
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd
        http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd 
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd ">


        <!--  configuration for handling browser back button  -->
    <mvc:interceptors>
        <mvc:interceptor>
            <mvc:mapping path="/**/*"/>
            <beans:bean id="webContentInterceptor" class="org.springframework.web.servlet.mvc.WebContentInterceptor">
                <beans:property name="cacheSeconds" value="0"/>
                <beans:property name="useExpiresHeader" value="true"/>
                <beans:property name="useCacheControlHeader" value="true"/>
                <beans:property name="useCacheControlNoStore" value="true"/>
            </beans:bean>
        </mvc:interceptor>
    </mvc:interceptors>

...
</beans>

但是我在编译时遇到了这个问题:

 org.xml.sax.SAXParseException; lineNumber: 19; columnNumber: 118; The prefix "beans" for element "beans:bean" is not bound.:org.xml.sax.SAXParseException:The prefix "beans" for element "beans:bean" is not bound.

1 个答案:

答案 0 :(得分:0)

尝试通过以下方式声明bean;)

<bean id="webContentInterceptor" class="org.springframework.web.servlet.mvc.WebContentInterceptor">
    <property name="cacheSeconds" value="0"/>
    <property name="useExpiresHeader" value="true"/>
    <property name="useCacheControlHeader" value="true"/>
    <property name="useCacheControlNoStore" value="true"/>
</bean>

或添加bean名称空间xmlns:beans = "http://www.springframework.org/schema/beans",如下所示;)

<?xml version="1.0" encoding="UTF-8" ?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:beans = "http://www.springframework.org/schema/beans"

    ... ...