close
import java.io.*;

import javax.servlet.*;

import javax.servlet.http.*;



public class CookieExample extends HttpServlet {



public void doGet(HttpServletRequest request, HttpServletResponse response)

throws IOException, ServletException

{

response.setContentType("text/html");

PrintWriter out = response.getWriter();



// print out cookies



Cookie[] cookies = request.getCookies();

for (int i = 0; i < cookies.length; i++) {

Cookie c = cookies[i];

String name = c.getName();

String value = c.getValue();

out.println(name + " = " + value);

}



// set a cookie



String name = request.getParameter("cookieName");

if (name != null && name.length() > 0) {

String value = request.getParameter("cookieValue");

Cookie c = new Cookie(name, value);

response.addCookie(c);

}

}

}
arrow
arrow
    全站熱搜
    創作者介紹
    創作者 alex0126 的頭像
    alex0126

    簡單看的清楚比較重要

    alex0126 發表在 痞客邦 留言(0) 人氣()