Post Reply 
 
Thread Rating:
  • 1 Votes - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Read a Cookie from a servlet
12-14-2010, 08:52 AM
Post: #1
Read a Cookie from a servlet
import javax.servlet.*;
import javax.servlet.http.*;

public class MyServlet extends HttpServlet {
public void doPost
(HttpServletRequest req, HttpServletResponse res) {
Cookie[] theCookies = request.getCookies();
if (theCookies != null) {
java.io.PrintWriter out = res.getWriter();
for (int i =0; i< cookies.length; i++) {
Cookie aCookie = theCookies[i];
out.println
("Name : " + aCookie.getName()
+ " Value: " + aCookie.getValue());
}
}
}

public void doGet(HttpServletRequest req, HttpServletResponse res) {
doPost(req, res);
}

}
Find all posts by this user
Quote this message in a reply
Post Reply 


Forum Jump:



Send your comments, Suggestions or Queries regarding this site at info@tutorials4u.net

Copyright © 2010 Tutorials4u.net All Rights Reserved