Advertisement
Guest User

Untitled

a guest
May 21st, 2018
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.98 KB | None | 0 0
  1. package com.grs.utils;
  2.  
  3. /**
  4.  * Created by Acer on 8/20/2017.
  5.  */
  6. import org.springframework.web.util.WebUtils;
  7.  
  8. import javax.servlet.http.Cookie;
  9. import javax.servlet.http.HttpServletRequest;
  10. import javax.servlet.http.HttpServletResponse;
  11.  
  12. public class CookieUtil {
  13.     public static void create(HttpServletResponse httpServletResponse, String name, String value) {
  14.         Cookie cookie = new Cookie(name, value);
  15.         httpServletResponse.addCookie(cookie);
  16.     }
  17.  
  18.     public static void clear(HttpServletResponse httpServletResponse, String name) {
  19.         Cookie cookie = new Cookie(name, null);
  20.         cookie.setPath("/");
  21.         cookie.setHttpOnly(true);
  22.         cookie.setMaxAge(0);
  23.         httpServletResponse.addCookie(cookie);
  24.     }
  25.  
  26.     public static String getValue(HttpServletRequest httpServletRequest, String name) {
  27.         Cookie cookie = WebUtils.getCookie(httpServletRequest, name);
  28.         return cookie != null ? cookie.getValue() : null;
  29.     }
  30. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement