程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> JSP編程 >> 關於JSP >> jsp servlet cookie 遍歷代碼

jsp servlet cookie 遍歷代碼

編輯:關於JSP

jsp教程 servlet cookie 遍歷代碼

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("<html>");
    out.println("<head>");
    out.println("<title>Servlet Cookie Information</title>");
    out.println("</head>");
    out.println("<body>");

    if ((cookies == null) || (cookies.length == 0)) {
      out.println("<center><h1>No Cookies found</h1>");
    } else {

      out.println("<center><h1>Cookies found</h1>");
      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("</html>");
    out.flush();
  }
}

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved