write Session Id To New Cookie - Java Servlet JSP

Java examples for Servlet JSP:Cookie

Description

write Session Id To New Cookie

Demo Code


import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.log4j.Logger;

public class Main{
    private static final String DISTRIBUTED_SESSION_ID = "JSESSIONID";
    /*from w  w w .  ja  v  a2s . c o m*/
    public static Cookie writeSessionIdToNewCookie(String id,
            HttpServletResponse response, int expiry) {
        Cookie cookie = new Cookie(DISTRIBUTED_SESSION_ID, id);
        cookie.setMaxAge(expiry);
        response.addCookie(cookie);
        return cookie;
    }
}

Related Tutorials