List of usage examples for javax.servlet.http Cookie setPath
public void setPath(String uri)
From source file:de.escidoc.core.common.servlet.UserHandleCookieUtil.java
/** * Creates an authentication cookie holding the provided eSciDoc user handle.<br> The cookie is valid for all * locations of the eSciDoc domain. Its max age is set to the value of the configuration parameter * escidoc.userHandle.cookie.lifetime.//from www . j a va 2s . c o m * * @param handle The eSciDocUserHandle. * @return Returns the created {@link Cookie}. * @throws WebserverSystemException Thrown in case of an internal error (configuration parameter not retrievable). */ public static Cookie createAuthCookie(final String handle) throws WebserverSystemException { final Cookie authCookie = new Cookie(EscidocServlet.COOKIE_LOGIN, handle); authCookie.setMaxAge(getEscidocCookieLifetime()); // Set the cookie for all locations of the escidoc domain authCookie.setPath("/"); return authCookie; }
From source file:net.shopxx.util.CookieUtils.java
/** * cookie//from w w w. j av a 2s . com * * @param request * HttpServletRequest * @param response * HttpServletResponse * @param name * cookie?? * @param path * * @param domain * */ public static void removeCookie(HttpServletRequest request, HttpServletResponse response, String name, String path, String domain) { Assert.notNull(request); Assert.notNull(response); Assert.hasText(name); Cookie cookie = new Cookie(name, null); cookie.setMaxAge(0); if (StringUtils.isNotEmpty(path)) { cookie.setPath(path); } if (StringUtils.isNotEmpty(domain)) { cookie.setDomain(domain); } response.addCookie(cookie); }
From source file:com.identityconcepts.shibboleth.WSFedLoginHandler.java
/** * set cookie for pass-through/*from w ww .j a va 2s . com*/ * cookieDomain can be configured in the handler config * * @param path path to which the client should return the cookie */ public static Cookie createCookie(String path) { Cookie cookie = new Cookie(COOKIE_NAME, "1"); cookie.setMaxAge(60 * 60 * 24 * 365); cookie.setPath(path); cookie.setSecure(true); // use cookieDomain if set if (!((cookieDomain == null) || (cookieDomain == ""))) { cookie.setDomain(cookieDomain); } return cookie; }
From source file:com.usefullc.platform.common.utils.CookieUtils.java
/** * cookie//from ww w . j ava 2s . com * * @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); }
From source file:com.rantop.web.util.web.ServletUtils.java
/** * Convenience method to set a cookie// w ww. java 2 s.c o m * * @param response * @param name * @param value * @param path */ public static void setCookie(HttpServletResponse response, String name, String value, String path) { if (log.isDebugEnabled()) { log.debug("Setting cookie '" + name + "' on path '" + path + "'"); } Cookie cookie = new Cookie(name, value); cookie.setSecure(false); cookie.setPath(path); cookie.setMaxAge(3600 * 24 * 30); // 30 days response.addCookie(cookie); }
From source file:com.bacic5i5j.framework.toolbox.web.WebUtils.java
/** * cookie?/* ww w.j av a 2s . com*/ * * @param response * @param name * @param value * @param domain * @param expiry */ public static void setCookie(HttpServletResponse response, String name, String value, String domain, int expiry) { Cookie cookie = new Cookie(name, value); cookie.setDomain(domain); cookie.setPath("/"); cookie.setMaxAge(expiry); response.addCookie(cookie); }
From source file:com.adobe.acs.commons.util.CookieUtil.java
/** * <p>/*from w ww . j a v a 2 s .co m*/ * Extend the cookie life. * <p></p> * This can be used when a cookie should be valid for X minutes from the last point of activity. * <p></p> * This method will leave expired or deleted cookies alone. * </p> * * @param request Request to get the Cookie from * @param response Response to write the extended Cookie to * @param cookieName Name of Cookie to extend the life of * @param expiry New Cookie expiry */ public static boolean extendCookieLife(final HttpServletRequest request, final HttpServletResponse response, final String cookieName, final String cookiePath, final int expiry) { final Cookie cookie = getCookie(request, cookieName); if (cookie == null) { return false; } if (cookie.getMaxAge() <= 0) { return false; } final Cookie responseCookie = (Cookie) cookie.clone(); responseCookie.setMaxAge(expiry); responseCookie.setPath(cookiePath); addCookie(responseCookie, response); return true; }
From source file:com.adobe.acs.commons.util.CookieUtil.java
/** * Internal method used for dropping cookies * * @param response//from w w w . j a v a 2 s . c om * @param cookies * @param cookiePath * @return */ private static int dropCookies(final HttpServletResponse response, final Cookie[] cookies, final String cookiePath) { int count = 0; for (final Cookie cookie : cookies) { if (cookie == null) { continue; } final Cookie responseCookie = (Cookie) cookie.clone(); responseCookie.setMaxAge(0); responseCookie.setPath(cookiePath); responseCookie.setValue(""); addCookie(responseCookie, response); count++; } return count; }
From source file:com.ax.utils.CookieUtils.java
/** * Stores a value in a cookie. This cookie will persist for the amount * specified in the <tt>saveTime</tt> parameter. * /*from w w w .j a va 2s .c o m*/ * @see #setCookie(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse,String,String) * @param request * the servlet request. * @param response * the servlet response. * @param name * a name to identify the cookie. * @param value * the value to store in the cookie. * @param maxAge * the time (in seconds) this cookie should live. * @param domain * the domain. * @param path * the path. */ public static void setCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, int maxAge, String domain, String path) { // Check to make sure the new value is not null (appservers like Tomcat // 4 blow up if the value is null). if (value == null) { value = ""; } if (StringUtils.isEmpty(path)) { path = "/"; } Cookie cookie = new Cookie(name, value); // maxAge0cookiemaxAge // if (maxAge > 0) // { cookie.setMaxAge(maxAge); // } cookie.setPath(path); // domain?cookiedomain if (!StringUtils.isEmpty(domain)) { cookie.setDomain(domain); } response.addCookie(cookie); }
From source file:com.kingcore.framework.util.CookieUtils.java
/** * Creates a Cookie with the specified name, value and max age, * and adds it to the response./*from w w w .j ava2 s. c o m*/ * cookies cookie?Base64 ? * 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's name. * @param value cookie's value. * @param maxAge the time cookie been keeped. the unit is second. * age of the cookie in seconds,??Cookie. * an integer specifying the maximum age of the cookie in seconds; * if negative, means the cookie is not stored; if zero, deletes the cookie. * @param res response Object. * @param needEncode ??Cookie?Base64?true * @param domain Cookie's domain */ public static void sendCookie(String name, String value, int maxAge, HttpServletResponse response, boolean needEncode, String domain) { try { if (needEncode) { value = Base64.encode(value.getBytes("utf-8")); //? // value = new String(Base64.encode( value.getBytes("utf-8")), "utf-8" ); //utf-8 } //System.out.println("value = " + value); Cookie cookie = new Cookie(name, value);//Hex.encode(value.getBytes()) ); cookie.setMaxAge(maxAge); cookie.setPath("/"); if (domain != null) { cookie.setDomain(domain); // domain } response.addCookie(cookie); } catch (UnsupportedEncodingException e) { log.debug("debug", e); /// e.pri ntStackTrace(); } }