其他分享
首页 > 其他分享> > Filter实际应用案例

Filter实际应用案例

作者:互联网

用户登录之后才能进入主页,用户注销之后就不能进入主页
1.用户登录之后,向session中放入用户的数据
2.进入主页时候要判断用户是否已经登录,在过滤器中实现

public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        HttpServletRequest request = (HttpServletRequest) servletRequest;
        HttpServletResponse response = (HttpServletResponse) servletResponse;
        Object user_session = request.getSession().getAttribute("USER_SESSION");
        if (user_session==null) {
            response.sendRedirect("/show/error.jsp");
        }
        filterChain.doFilter(servletRequest,servletResponse) ;
    }

标签:登录,主页,servletResponse,用户,Filter,案例,session,应用,servletRequest
来源: https://www.cnblogs.com/UltraBlast/p/14401449.html