草原上一间小屋 2011-03-08
欢迎大家访问我的个人网站 萌萌的IT人,后续所有的文章都会在此发布
--------------------------------------------------------------------------------------------public static void writeLoginCookie(CallingCard callingCard, HttpServletResponse response) { StringBuilder builder = new StringBuilder(); builder.append(callingCard.getCellPhone()).append("#").append(...); String cookieString; try { cookieString = CookieUtil.enCode(builder.toString()); } catch (Exception e) { cookieString = builder.toString(); } Cookie loginCookie = new Cookie("loginCookie", cookieString); loginCookie.setPath("/"); response.addCookie(loginCookie); }
public static void readCallingCard(HttpServletRequest request, CallingCard callingCard) { Cookie cookies[] = request.getCookies(); if (cookies != null && cookies.length > 0) { Cookie acookie[] = cookies; int i = 0; for (int j = acookie.length; i < j; i++) { Cookie cookie = acookie[i]; String name = cookie.getName(); if ("loginCookie".equalsIgnoreCase(name)) { String loginValue = cookie.getValue(); try { loginValue = CookieUtil.deCode(loginValue); } catch (Exception e) { loginValue = cookie.getValue(); } if (StringUtils.isEmpty(loginValue)) { logger.error("login cookie is empty"); } else { String login[] = loginValue.split("#"); readCallingCard(callingCard, login); } } } } }