Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.grs.utils;
- /**
- * Created by Acer on 8/20/2017.
- */
- import org.springframework.web.util.WebUtils;
- import javax.servlet.http.Cookie;
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- public class CookieUtil {
- public static void create(HttpServletResponse httpServletResponse, String name, String value) {
- Cookie cookie = new Cookie(name, value);
- httpServletResponse.addCookie(cookie);
- }
- public static void clear(HttpServletResponse httpServletResponse, String name) {
- Cookie cookie = new Cookie(name, null);
- cookie.setPath("/");
- cookie.setHttpOnly(true);
- cookie.setMaxAge(0);
- httpServletResponse.addCookie(cookie);
- }
- public static String getValue(HttpServletRequest httpServletRequest, String name) {
- Cookie cookie = WebUtils.getCookie(httpServletRequest, name);
- return cookie != null ? cookie.getValue() : null;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement