csp writeCookie
欢迎大家访问我的个人网站 萌萌的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); } } } } }
相关推荐
湾区人工智能 2020-11-20
diskingchuan 2020-10-23
amicablehj 2020-11-16
smartbaby 2020-11-11
teamvx 2020-11-11
啊兵 2020-11-10
ruancw 2020-11-10
Elyn 2020-11-08
susmote 2020-11-07
lipin 2020-11-03
kinglomei 2020-10-27
bucai 2020-10-26
JAVA飘香 2020-10-26
重剑无锋 2020-10-25
adentheima 2020-10-25
zhaoyinghuan 2020-10-25
Elyn 2020-10-24
lipin 2020-10-22
feinifi 2020-10-14