Exemplo n.º 1
0
  public static String getCookieValue(HttpServletRequest request, String name) {
    try {
      Cookie cookie = getCookie(request, name);
      if (cookie != null) {
        String decode1 = URLDecoder.decode(cookie.getValue(), "UTF-8");

        String decode = DESede.decode(decode1);
        log.debug("getCookieValue :" + decode);
        return decode;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return null;
  }
Exemplo n.º 2
0
  public static void setCookie(
      HttpServletResponse response, String name, String value, int maxAge) {
    if (value == null) value = "";

    Cookie cookie;
    try {
      log.debug("setCookie :" + name + "-" + value);
      String encode = DESede.encode(value);
      encode = URLEncoder.encode(encode, "UTF-8");
      cookie = new Cookie(name, encode);
      cookie.setMaxAge(maxAge > 0 ? maxAge : COOKIE_MAX_AGE);
      cookie.setPath("/");
      cookie.setHttpOnly(true);
      response.addCookie(cookie);
    } catch (Exception e) {
      e.printStackTrace();
    }
  }