List of usage examples for javax.servlet.http HttpServletResponse addCookie
public void addCookie(Cookie cookie);
From source file:com.eryansky.common.web.utils.RequestUtil.java
public static void setCookie(HttpServletResponse response, String name, String value, String path) { if (logger.isDebugEnabled()) { logger.debug("Cookie '" + name + "',?: '" + path + "'"); }/*from w ww . j a v a 2s . c o m*/ Cookie cookie = new Cookie(name, value); cookie.setSecure(false); cookie.setPath(path); cookie.setMaxAge(2592000); response.addCookie(cookie); }
From source file:com.kingcore.framework.util.CookieUtils.java
/** * domain clearCookie// www .j a v a2s . co m * The form of the domain name is specified by RFC 2109. A domain name begins with a dot (.foo.com) * and means that the cookie is visible to servers in a specified Domain Name System (DNS) zone * (for example, www.foo.com, but not a.b.foo.com). By default, cookies are only returned to * the server that sent them. * @param name ?Cookie?? * @param response ? * @param domain Cookie?? */ public static void clearCookie(String name, HttpServletResponse response, String domain) { Cookie cookie = new Cookie(name, null); cookie.setMaxAge(0); cookie.setPath("/"); cookie.setDomain(domain); response.addCookie(cookie); }
From source file:ru.org.linux.csrf.CSRFProtectionService.java
public static void generateCSRFCookie(HttpServletRequest request, HttpServletResponse response) { SecureRandom random = new SecureRandom(); byte[] value = new byte[16]; random.nextBytes(value);//from w ww .j a v a2s. com String token = new String(Base64.encodeBase64(value)); Cookie cookie = new Cookie(CSRF_COOKIE, token); cookie.setMaxAge(TWO_YEARS); cookie.setPath("/"); response.addCookie(cookie); request.setAttribute(CSRF_ATTRIBUTE, token); }
From source file:cn.vlabs.duckling.vwb.VWBFilter.java
public static void removeGlobalCookie(HttpServletRequest request, HttpServletResponse response, HttpSession session) {//from w w w. ja v a2 s .c o m Cookie oldCookie = new Cookie(COOKIE_NAME, session.getId()); oldCookie.setPath(request.getContextPath()); oldCookie.setMaxAge(0); response.addCookie(oldCookie); }
From source file:com.liusoft.dlog4j.util.RequestUtils.java
/** * FCKUpload?Cookie/*from w ww. ja v a 2 s . c om*/ * @param req * @param res */ public static void clearDlogSessionId(HttpServletRequest req, HttpServletResponse res) { Cookie cok = RequestUtils.getCookie(req, Globals.SESSION_ID_KEY_IN_COOKIE); if (cok != null) { cok.setMaxAge(0); res.addCookie(cok); } }
From source file:com.kingcore.framework.util.CookieUtils.java
/** * domain,path ? clearCookie//from w ww .j av a 2 s .c o m * The form of the domain name is specified by RFC 2109. A domain name begins with a dot (.foo.com) * and means that the cookie is visible to servers in a specified Domain Name System (DNS) zone * (for example, www.foo.com, but not a.b.foo.com). By default, cookies are only returned to * the server that sent them. * @param name ?Cookie?? * @param response ? * @param domain Cookie?? * @param path Cookie? */ public static void clearCookie(String name, HttpServletResponse response, String domain, String path) { Cookie cookie = new Cookie(name, null); cookie.setMaxAge(0); cookie.setPath(path); cookie.setDomain(domain); response.addCookie(cookie); }
From source file:com.ieasy.basic.util.CookieSupport.java
/** * cookies/*w ww . j a va2s .c o m*/ * * @param response * @param cookieParams * @param maxAge */ public static final void writeCookies(HttpServletResponse response, Map<String, String> cookieParams, int maxAge) { if (cookieParams == null || cookieParams.size() == 0) return; Set<String> keySet = cookieParams.keySet(); for (String key : keySet) { Cookie cookie = new Cookie(key, cookieParams.get(key)); cookie.setMaxAge(maxAge); response.addCookie(cookie); } }
From source file:org.apache.archiva.redback.integration.util.AutoLoginCookies.java
private static void removeCookie(HttpServletResponse response, HttpServletRequest httpRequest, String cookieName, String domain, String path) { Cookie cookie = createCookie(cookieName, "", domain, path, httpRequest); cookie.setMaxAge(0);/*from w ww. j a v a 2 s .co m*/ response.addCookie(cookie); }
From source file:org.b3log.latke.util.Sessions.java
/** * Logouts a user with the specified request. * * @param request the specified request/*from w w w . j a va 2 s. com*/ * @param response the specified response * @return {@code true} if succeed, otherwise returns {@code false} */ public static boolean logout(final HttpServletRequest request, final HttpServletResponse response) { final HttpSession session = request.getSession(false); if (null != session) { final Cookie cookie = new Cookie("b3log-latke", null); cookie.setMaxAge(0); cookie.setPath("/"); response.addCookie(cookie); session.invalidate(); return true; } return false; }
From source file:com.usefullc.platform.common.utils.CookieUtils.java
/** * cookie/*from w ww .j a v a2s . c o m*/ * * @param response * @param name * @param value * @param domain * @param expire */ public static void addCookie(HttpServletResponse response, String name, String value, String domain, Integer expire) { Cookie cookie = new Cookie(name, value); if (StringUtils.isNotEmpty(domain)) { cookie.setDomain(domain); } if (expire != null) { cookie.setMaxAge(expire); } cookie.setPath("/"); response.addCookie(cookie); }