Set a Cookie from a servletFrom WikiJava
This example shows how to set a cookie in the response to a request from a client browser.
the articleThis example uses the Cookie class and the HttpServletRequest to send a cookie. the fundamental method used is: HttpServletRequest.addCookie MyServletimport 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); } } See Also |
