Jump to Real's How-to Main page

Set a Cookie from a servlet

import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet extends HttpServlet {
  public void doPost(HttpServletRequest req, HttpServletResponse res) {
    res.addCookie(new Cookie("mycookie_name", "mycookie_value"));
    }
    
  public void doGet(HttpServletRequest req, HttpServletResponse res) {
    doPost(req, res);
    }
    
}


If you find this article useful, consider making a small donation
to show your support for this Web site and its content.

Written and compiled by Réal Gagnon ©1998-2005
[ home ]