数据存放在cookies

public static final String DEFAULT_SESSION_ID_KEY = "SESSION_ID_KEY";

@Override
public String setSessionIDCookie(HttpServletRequest request, String userid, HttpServletResponse response) throws OAuthSystemException {
	String sessionid = CodeUtil.encodeByMD5(valueGenerator.generateValue() + userid);
	Cookie cookie = new Cookie(DEFAULT_SESSION_ID_KEY, sessionid);
	cookie.setPath("/");
	// 表示关闭浏览器cookie过期
	response.addCookie(cookie);
	return sessionid;
}

@Override
public String getSessionIDCookie(HttpServletRequest request) throws OAuthSystemException {
	// TODO Auto-generated method stub
	Cookie[] cookies = request.getCookies();
	if (cookies != null && cookies.length > 0) {
		for (Cookie c : cookies) {
			if (c.getName().equals(DEFAULT_SESSION_ID_KEY)) {
				return c.getValue();
			}
		}
	}
	return null;
}

@Override
public void delSessionIDCookie(HttpServletRequest request, HttpServletResponse response) throws OAuthSystemException {
	Cookie cookie = new Cookie(DEFAULT_SESSION_ID_KEY, "");
	cookie.setMaxAge(0);
	response.addCookie(cookie);
}

相关推荐