日期:2014-05-17 浏览次数:20825 次
import java.io.IOException; import java.io.PrintWriter; import javax.servlet.ServletException; import javax.servlet.http.*; public class HelloWorldServlet extends HttpServlet { @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { System.out.println("doGet"); response.getWriter().write("<a href = 'www.baidu.com'>go</a>"); Cookie cookie = new Cookie("名字1", "值1"); cookie.setMaxAge(3600); response.addCookie(cookie); cookie = new Cookie("名字2", "值2"); response.addCookie(cookie); PrintWriter out = response.getWriter(); Cookie[] allCookie = request.getCookies(); for (Cookie c : allCookie) { out.println(c.getName() + " and " + c.getValue() + "<br/>"); } } }