java使用Cookie判断用户登录情况

1.判断是否登录

public boolean isLogin() {
        Set<Cookie> cookies = this.browser.getCookies();
        String JSESSIONIDID = "JSESSIONID";
        String sessionIdID = "sessionId";
        String loginID = "login";
        String JSESSIONIDIDValue = "";
        String sessionIdValue = "";
        String loginValue = "";
        for (Cookie c:cookies) {
            logger.info(c.getName() + ": " +  c.getValue());
            if (c.getName().equals(JSESSIONIDID)) {
                JSESSIONIDIDValue = c.getValue();
            } else if(c.getName().equals(sessionIdID)) {
                sessionIdValue = c.getValue();
            } else if (c.getName().equals(loginID)) {
                loginValue = c.getValue();
            }
        }        
        if ( JSESSIONIDIDValue.equals(sessionIdValue) & loginValue.equals("login")) {
            return true;
        } else {
            return false;
        }
    }

2.页面登录cookie

.

 

posted @ 2017-12-19 11:52  Sunny*  阅读(3339)  评论(0编辑  收藏  举报