zoukankan      html  css  js  c++  java
  • filter实现登陆拦截

    代码
    package com.ucit.filter;

    import java.io.IOException;
    import java.util.ArrayList;
    import javax.servlet.Filter;
    import javax.servlet.FilterChain;
    import javax.servlet.FilterConfig;
    import javax.servlet.ServletException;
    import javax.servlet.ServletRequest;
    import javax.servlet.ServletResponse;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;

    import com.ucit.struts.action.LoginAction;

    public class TuserCheckFilter implements Filter {

        
    public void destroy() {
            
    // TODO Auto-generated method stub

        }

        
    static ArrayList<HttpSession> tusers = LoginAction.tusers;

        
    public void doFilter(ServletRequest arg0, ServletResponse arg1,
                FilterChain arg2) 
    throws IOException, ServletException {
            
    // 当前SESSION不在Tusers里的时候,就让他跳到登陆页面

            HttpSession nowSession 
    = ((HttpServletRequest) arg0).getSession();

            
    boolean in = false;
            
    for (int i = 0; i < tusers.size(); i++) {
                
    if (nowSession == tusers.get(i)) {
                    in 
    = true;
                    
    break;
                }
            }

            
    if (!in) {
                
    if (!((HttpServletRequest) arg0).getServletPath().equals(
                        
    "/login.jsp"))

                {
                    ((HttpServletResponse) arg1)
                            .sendRedirect(
    "/oracleManagement/login.jsp");
                } 
    else {
                    arg2.doFilter(arg0, arg1);
                }
                ;

            } 
    else {

                arg2.doFilter(arg0, arg1);
            }

        }

        
    public void init(FilterConfig arg0) throws ServletException {
            
    // TODO Auto-generated method stub

        }

    }
  • 相关阅读:
    REST Security with JWT using Java and Spring Security
    UserMapper.selectByPrimaryKey-Inline 报错的解决办法
    Nginx反向代理,负载均衡,redis session共享,keepalived高可用
    HTML 5 Web 存储-localStorage
    Android之自定义checkbox样式
    android fragment传递参数_fragment之间传值的两种方法
    linux常用基本命令
    fragment点击跳转到外部Activity后,怎么通过返回按钮返回
    android 中FragmentActivity中模拟返回键返回上一个Activity效果
    Fragment与Activity相互传递数据:
  • 原文地址:https://www.cnblogs.com/jifeng/p/1857424.html
Copyright © 2011-2022 走看看