How to add cookie in servlet?

 
 

Question

How to add cookie in servlet?

Re: How to add cookie in servlet?

The cookie is added to the Set-Cookie response header by means of the addCookie method of HttpServletResponse. Here's an example:
Cookie userCookie = new Cookie("user", "uid1234");
response.addCookie(userCookie);