p; if (uri.indexOf(string) > -1)
{
return true;
}
}
return false;
}
}
上面提到的对静态资源不过滤,当然springmvc中也要设置静态资源的请求不经过DispatcherServlet,此时就需要在spring-mvc.xml中进行设置,小编基本使用默认的配置,如下代码中的<mvc:default-servlet-handler />
<?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:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-4.3.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-4.3.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-4.3.xsd ">
<context:component-scan base-package="com.yongcheng.liuyang.controller">
</context:component-scan>
<context:component-scan base-package="com.yongcheng.liuyang.listener" />
<!-- spring MVC不处理静态资源 -->
<mvc:default-servlet-handler />
<!-- 支持MVC的注解驱动 -->
<mvc:annotation-driven />
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver"
id="internalResourceViewResolver" >
<!-- 自动添加到路径中的前缀 -->
<property name="prefix" value="/jsp/" />
<!-- 自动添加到路径中的后缀 -->
<property name="suffix" value=".jsp" />
</bean>
</beans>
好了,以上就是springmvc中简答的filter使用!如有任何疑问,欢迎留言交流!!