Home
JAVA SERVLET
Writing Cookies
To send a cookie
Instantiate a Cookieobject
Set any attributes
Send the cookie
Here is an example code to send cookie to the client
import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class cook extends HttpServlet { String uid; Cookie cok; public void doPost(HttpServletRequest req,HttpServletResponse res) throws IOException, ServletException { PrintWriter pw = res.getWriter(); uid = req.getParameter("txtuid"); cok = new Cookie("UserID",uid); cok.setMaxAge(1000000); res.addCookie(cok); pw.println("Cooooooooooooooookies"); pw.close(); } }
Previous
Next