1 30 31 package org.apache.commons.httpclient; 32 33 import java.io.*; 34 import javax.servlet.*; 35 import javax.servlet.http.*; 36 import javax.servlet.http.Cookie ; 37 import java.util.*; 38 39 public class ReadCookieServlet extends MultiMethodServlet { 40 protected void genericService(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { 41 response.setContentType("text/html"); 42 PrintWriter out = response.getWriter(); 43 out.println("<html>"); 44 out.println("<head><title>ReadCookieServlet: " + request.getMethod() + "</title></head>"); 45 out.println("<body>"); 46 out.println("<p>This is a response to an HTTP " + request.getMethod() + " request.</p>"); 47 Enumeration enumeration = request.getHeaders("Cookie"); 48 while (enumeration.hasMoreElements()) { 49 out.println("<p><tt>Cookie: " + (String )enumeration.nextElement() + "</tt></p>"); 50 } 51 Cookie[] cookies = request.getCookies(); 52 if(null != cookies) { 53 for(int i=0;i<cookies.length;i++) { 54 out.println("<tt>" + cookies[i].getName() + "=" + cookies[i].getValue() + "</tt><br>"); 55 } 56 } 57 out.println("</body>"); 58 out.println("</html>"); 59 } 60 } 61 62 | Popular Tags |