package devmanuals;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class SetCookie extends HttpServlet {
	PrintWriter pw = null;

	public void doGet(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		// Invoke the doPost() method of HttpServlet class
		doPost(req, res);
	}

	public void doPost(HttpServletRequest req, HttpServletResponse res)
			throws ServletException, IOException {
		pw = res.getWriter();
		/* Retrieve the user information from HttpServlet request. */
		String username = req.getParameter("user");
		String password = req.getParameter("password");
		/* Create a cookie that contains username. */
		Cookie ck = new Cookie("user", username);
		/* Add the cookie to the client browser. */
		res.addCookie(ck);
		pw.println("Cookie containing user name is stored in your browser.");
	}
}
