Example usage for javax.servlet.http HttpServletResponse addCookie

List of usage examples for javax.servlet.http HttpServletResponse addCookie

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse addCookie.

Prototype

public void addCookie(Cookie cookie);

Source Link

Document

Adds the specified cookie to the response.

Usage

From source file:com.alfaariss.oa.util.web.CookieTool.java

/**
 * Remove cookie.//  w  w w.  ja v  a2s  .  c  o  m
 * @param sCookie The cookie name.
 * @param oRequest The servlet request.
 * @param oResponse The servlet response.
 */
public void removeCookie(String sCookie, HttpServletRequest oRequest, HttpServletResponse oResponse) {
    Cookie cookie = createCookie(sCookie, "jimmorrisonisstillalive", oRequest);
    cookie.setMaxAge(0); //Expire                        
    oResponse.addCookie(cookie);
}

From source file:com.tenduke.example.scribeoauth.SessionManager.java

/**
 * Terminates session.//from  w w  w .  ja  v  a2 s.c om
 * @param request Client HTTP request.
 * @param response HTTP response.
 */
public void endSession(final HttpServletRequest request, final HttpServletResponse response) {
    //
    final Cookie cookie = new Cookie(SIGNED_SESSION_COOKIE_NAME, null);
    cookie.setMaxAge(0);
    cookie.setPath("/");
    response.addCookie(cookie);
}

From source file:com.mawujun.util.web.CookieGenerator.java

/**
 * Add a cookie with the given value to the response,
 * using the cookie descriptor settings of this generator.
 * <p>Delegates to <code>createCookie</code> for cookie creation.
 * @param response the HTTP response to add the cookie to
 * @param cookieValue the value of the cookie to add
 * @see #setCookieName//from  w  w w  .j  a v a 2 s. c o m
 * @see #setCookieDomain
 * @see #setCookiePath
 * @see #setCookieMaxAge
 * @see #createCookie
 */
public void addCookie(HttpServletResponse response, String cookieValue) {
    Cookie cookie = createCookie(cookieValue);
    cookie.setMaxAge(getCookieMaxAge());
    if (isCookieSecure()) {
        cookie.setSecure(true);
    }
    response.addCookie(cookie);
    if (logger.isDebugEnabled()) {
        logger.debug("Added cookie with name [" + getCookieName() + "] and value [" + cookieValue + "]");
    }
}

From source file:fr.mby.opa.login.web.controller.LoginController.java

/**
 * @param model/*ww w . ja v  a2 s . c o m*/
 * @param request
 */
protected void initView(final ModelMap model, final HttpServletRequest request,
        final HttpServletResponse response) {
    final IApp thisApp = this.portalService.getTargetedApp(request);
    model.addAttribute("app", thisApp);
    model.addAttribute("loginForm", new LoginForm());

    response.addCookie(new Cookie(IPortal.SIGNATURE_PARAM_NAME, thisApp.getSignature()));
}

From source file:com.mobileman.projecth.web.util.PersistentCookieHelper.java

public void setUser(HttpServletResponse response, User user) {
    String hash = createHash("" + System.currentTimeMillis(), user);
    //save hash to cvookie
    Cookie cookie = new Cookie(COOKIE_NAME, hash);
    cookie.setPath(PATH);/* w w  w .ja v  a  2 s .  co  m*/
    cookie.setMaxAge(365 * 24 * 3600);

    response.addCookie(cookie);
}

From source file:com.baron.bm.controller.MemberController.java

@RequestMapping("/login")
public ModelAndView login(HttpServletResponse response, MemberModel model) {

    ModelAndView mav = new ModelAndView("loginResult");
    model = joinService.login(model);/* w w w . jav  a 2 s .  c  o  m*/
    if (model != null) {
        System.out.println(model.getId() + model.getPermission());
        response.addCookie(new Cookie("bm_id", model.getId()));
        response.addCookie(new Cookie("bm_permission", model.getPermission()));
        mav.addObject("result", true);
    } else {
        mav.addObject("result", false);
    }
    return mav;
}

From source file:com.flipkart.poseidon.core.PoseidonServlet.java

private void setCookies(PoseidonResponse response, HttpServletResponse httpResponse) {
    Map<String, Cookie> cookies = response.getCookies();
    for (Cookie cookie : cookies.values()) {
        httpResponse.addCookie(cookie);
    }/*from   w w  w. jav  a 2  s . com*/
}

From source file:com.persistent.cloudninja.web.security.CloudNinjaRemembermeService.java

/**
 * On logout, invalidate the cookie and send back in the response
 *//*  ww w . jav  a  2  s  .  c  om*/
public void logout(HttpServletRequest request, HttpServletResponse response, Authentication authentication) {
    String cookieName = getCookieName();
    Cookie cookieToInvalidate = getCoockieFromRequest(request, cookieName);
    if (null != cookieToInvalidate) {
        cookieToInvalidate.setMaxAge(0);
        cookieToInvalidate.setPath("/");
        response.addCookie(cookieToInvalidate);
    }
    cookieToInvalidate = getCoockieFromRequest(request, "CLOUDNINJALOGO");
    if (null != cookieToInvalidate) {
        cookieToInvalidate.setMaxAge(0);
        cookieToInvalidate.setPath("/");
        response.addCookie(cookieToInvalidate);
    }
}

From source file:co.id.app.sys.util.StringUtils.java

/**
 * Sets the given cookie values in the servlet response.
 * <p/>/*  ww w . j  ava 2  s  .  c o  m*/
 * This will also put the cookie in a list of cookies to send with this request's response
 * (so that in case of a redirect occurring down the chain, the first filter
 * will always try to set this cookie again)
 * <p/>
 * The cookie secure flag is set if the request is secure.
 * <p/>
 * This method was derived from Atlassian <tt>CookieUtils</tt> method of
 * the same name, release under the Apache License.
 *
 * @param request the servlet request
 * @param response the servlet response
 * @param name the cookie name
 * @param value the cookie value
 * @param maxAge the maximum age of the cookie in seconds. A negative
 * value will expire the cookie at the end of the session, while 0 will delete
 * the cookie.
 * @param path the cookie path
 * @return the Cookie object created and set in the response
 */
public static Cookie setCookie(HttpServletRequest request, HttpServletResponse response, String name,
        String value, int maxAge, String path) {

    Cookie cookie = new Cookie(name, value);
    cookie.setMaxAge(maxAge);
    cookie.setPath(path);
    cookie.setSecure(request.isSecure());
    response.addCookie(cookie);

    return cookie;
}

From source file:com.campodejazayeri.wedding.InviteController.java

@RequestMapping("/invite")
public String invite(@RequestParam(value = "code", required = false) String codeFromRequest,
        HttpServletResponse response,
        @CookieValue(value = "campodejazayeri_id", required = false) String groupId, Model model) {
    if (codeFromRequest != null) {
        groupId = codeFromRequest;// www . j ava2s  .c o m
        response.addCookie(new Cookie("campodejazayeri_id", codeFromRequest));
    }

    InvitationGroup group = getGroup(groupId);
    model.addAttribute("group", group);

    GuestBookPost lastPost = getLast(GuestBookPost.class, "guestbook", "posts");
    model.addAttribute("lastPost", lastPost);

    return "invite";
}