List of usage examples for javax.servlet.http Cookie setPath
public void setPath(String uri)
From source file:org.b3log.latke.util.Sessions.java
/** * Logouts a user with the specified request. * * @param request the specified request//from ww w . j a va 2s . c om * @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:architecture.ee.web.util.CookieUtils.java
public static void deleteCookie(HttpServletRequest request, HttpServletResponse response, Cookie cookie) { if (cookie != null) { String path = request.getContextPath() != null ? request.getContextPath() : "/"; if ("".equals(path)) path = "/"; cookie.setPath(path); cookie.setValue(""); cookie.setMaxAge(0);//w w w . jav a 2s .c o m response.addCookie(cookie); } }
From source file:edu.utah.further.i2b2.hook.further.web.ServletUtil.java
/** * Convenience method to set a cookie. The cookie gets max age set to 30 days. * * @param response//w ww . j a v a2 s . c o m * response that will accept a cookie * @param name * name of the cookie to store * @param value * value of the cookie * @param path * path of the cookie */ public static void setCookie(final HttpServletResponse response, final String name, final String value, final String path) { if (log.isDebugEnabled()) { log.debug("Setting cookie " + quote(name) + " on path " + quote(path)); } final 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.erudika.scoold.utils.HttpUtils.java
/** * Sets a cookie./* w ww . j av a2s . co m*/ * @param name the name * @param value the value * @param req HTTP request * @param res HTTP response * @param httpOnly HTTP only flag * @param maxAge max age */ public static void setRawCookie(String name, String value, HttpServletRequest req, HttpServletResponse res, boolean httpOnly, int maxAge) { if (StringUtils.isBlank(name) || value == null || req == null || res == null) { return; } Cookie cookie = new Cookie(name, value); cookie.setHttpOnly(httpOnly); cookie.setMaxAge(maxAge < 0 ? Config.SESSION_TIMEOUT_SEC : maxAge); cookie.setPath("/"); cookie.setSecure(req.isSecure()); res.addCookie(cookie); }
From source file:com.kingcore.framework.util.CookieUtils.java
/** * ? domain clearCookie//from w w w . j av a 2 s . c o m * clear a cookie from client side. * @param name the name of cookie will be cleared. * @param response HttpServletResponse Object. */ public static void clearCookie(String name, HttpServletResponse response) { Cookie cookie = new Cookie(name, null); cookie.setMaxAge(0); cookie.setPath("/"); response.addCookie(cookie); }
From source file:com.kingcore.framework.util.CookieUtils.java
/** * domain clearCookie//w ww . j av a 2s . 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?? */ 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:com.kingcore.framework.util.CookieUtils.java
/** * domain,path ? clearCookie//from w w w. j av a 2 s .c om * 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:alpha.portal.webapp.util.RequestUtil.java
/** * Convenience method for deleting a cookie by name. * //w ww.j a v a 2s .c o m * @param response * the current web response * @param cookie * the cookie to delete * @param path * the path on which the cookie was set (i.e. /appfuse) */ public static void deleteCookie(final HttpServletResponse response, final Cookie cookie, final String path) { if (cookie != null) { // Delete the cookie by setting its maximum age to zero cookie.setMaxAge(0); cookie.setPath(path); response.addCookie(cookie); } }
From source file:com.activecq.api.utils.CookieUtil.java
/** * Removes all cookies for the domain// w w w . j a v a 2 s . c o m * * @param request Request to get the Cookies to drop * @param response Response to expire the Cookies on */ public static int dropAllCookies(HttpServletRequest request, HttpServletResponse response) { int count = 0; Cookie[] cookies = request.getCookies(); if (cookies == null) { return 0; } for (Cookie cookie : cookies) { cookie.setMaxAge(0); cookie.setPath(cookie.getPath()); addCookie(cookie, response); count++; } return count; }
From source file:net.shopxx.util.CookieUtils.java
/** * cookie// w ww .j a v a 2s . co m * * @param request * HttpServletRequest * @param response * HttpServletResponse * @param name * cookie?? * @param value * cookie * @param path * * @param maxAge * (??: ) * @param domain * * @param secure * ?? */ public static void addCookie(HttpServletRequest request, HttpServletResponse response, String name, String value, String path, Integer maxAge, String domain, Boolean secure) { Assert.notNull(request); Assert.notNull(response); Assert.hasText(name); try { value = URLEncoder.encode(value, "UTF-8"); Cookie cookie = new Cookie(name, value); if (StringUtils.isNotEmpty(path)) { cookie.setPath(path); } if (maxAge != null) { cookie.setMaxAge(maxAge); } if (StringUtils.isNotEmpty(domain)) { cookie.setDomain(domain); } if (secure != null) { cookie.setSecure(secure); } response.addCookie(cookie); } catch (UnsupportedEncodingException e) { e.printStackTrace(); } }