读cookie
写cookie
//读取cookie
String loginType = "";
String strgrouploginid = "";
String strloginid = "";
Cookie[] cookies = request.getCookies();
if(cookies!=null)
{
for (int i = 0; i < cookies.length; i++ )
{
Cookie c = cookies[i];
if(c.getName().equalsIgnoreCase("loginType"))
{
loginType = c.getValue();
}
else if(c.getName().equalsIgnoreCase("strgrouploginid"))
{
strgrouploginid = c.getValue();
}
else if(c.getName().equalsIgnoreCase("strloginid"))
{
strloginid = c.getValue();
}
}
}
写cookie
private void setCookie(String loginType,String strgrouploginid,String strloginid,HttpServletRequest request,HttpServletResponse response)
{
//清除cookie
Cookie[] cookies = request.getCookies();
if(cookies!=null)
{
for (int i = 0; i < cookies.length; i++ )
{
Cookie c = cookies[i];
if(c.getName().equalsIgnoreCase("loginType"))
{
Cookie loginTypeCookie = new Cookie("loginType",null);
response.addCookie(loginTypeCookie);
}
else if(c.getName().equalsIgnoreCase("strgrouploginid"))
{
Cookie strgrouploginidCookie = new Cookie("strgrouploginid",null);
response.addCookie(strgrouploginidCookie);
}
else if(c.getName().equalsIgnoreCase("strloginid"))
{
Cookie strloginidCookie = new Cookie("strloginid",null);
response.addCookie(strloginidCookie);
}
}
}
//写cookie
Cookie loginTypeCookie = new Cookie("loginType",loginType);
Cookie strgrouploginidCookie = new Cookie("strgrouploginid",strgrouploginid);
Cookie strloginidCookie = new Cookie("strloginid",strloginid);
loginTypeCookie.setMaxAge(COOKIE_ALIVE_TIME);
strgrouploginidCookie.setMaxAge(COOKIE_ALIVE_TIME);
strloginidCookie.setMaxAge(COOKIE_ALIVE_TIME);
response.addCookie(loginTypeCookie);
response.addCookie(strgrouploginidCookie);
response.addCookie(strloginidCookie);
}