spring filter 代码 demo

2018-01-02

41

0

技术:spring filter

运行环境:IDEA 15.2 + jdk8 + windows 7 + spring-5.0.0.RELEASE

demo功能:提供一个spring filter基本接入

添加过滤器代码

/**
 * Created by francis on 2018/1/3.
 */
public class SessionFilter extends OncePerRequestFilter {
    @Override
    protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, FilterChain filterChain) throws ServletException, IOException {
        System.out.println("====测试Filter功能====拦截用户登陆====");
        filterChain.doFilter(httpServletRequest, httpServletResponse);//不执行过滤,继续执行操作
    }
}

web.xml注册过滤器

<filter>
<filter-name>sessionFilter</filter-name>
<filter-class>com.ctrip.filters.SessionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>sessionFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

启动测试

http://localhost:8080/

 

 

欢迎添加微信,互相学习↑↑↑ -_-

发表评论

全部评论:0条

白老虎

programming is not only to solve problems, ways to think