Jsp tutorial servlet cookie traversal code
Import java. io. IOException;
Import java. io. PrintWriter;
Import javax. servlet. ServletException;
Import javax. servlet. http. Cookie;
Import javax. servlet. http. HttpServlet;
Import javax. servlet. http. HttpServletRequest;
Import javax. servlet. http. HttpServletResponse;
Public class Cookies extends HttpServlet {
Public void doGet (HttpServletRequest req, HttpServletResponse resp) throws ServletException,
IOException {
Resp. setContentType ("text/html ");
Req. getSession ();
PrintWriter out = resp. getWriter ();
Cookie cookies [] = req. getCookies ();
Out. println ("Out. println ("Out. println ("<title> Servlet Cookie Information </title> ");
Out. println ("Out. println ("<body> ");
If (cookies = null) | (cookies. length = 0 )){
Out. println ("<center> } Else {
Out. println ("<center> For (int I = 0; I <cookies. length; I ++ ){
Cookie c = cookies [I];
Out. println (c. getName () + ":" + c. getValue () + "::"
+ C. getComment () + ":" + c. getMaxAge () + "<BR/> ");
}
Out. println ("</table> </center> ");
}
Out. println ("</body> ");
Out. println ("Out. flush ();
}
}