Java examples for Servlet JSP:Cookie
write Session Id To New Cookie
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; } }