HttpServletrequest usage

Hi everyone,

I am very new to java and I am having problems reading cookies from my browser store.

I am thinking that I have to use the getCookies on HttpServletRequest object. However, I don't know how to initalize this object.

My guess is that the HttpServletRequest object can only be initialized by a jsp. If thats true, is there another way of reading the cookies from my browser store? Below is a smaple piece of code, but I don't know how to test it?

publicvoid 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());

}

}

}

publicvoid doGet(HttpServletRequest req, HttpServletResponse res){

doPost(req, res);

}

What do code do I write in my main method to call doGet()req, res) method.

Thanks!

moy

[1656 byte] By [moy021a] at [2007-11-26 16:21:03]
# 1
It looks like You are going to write stand along application for that. If so it is wrong way.I would recommend You to create a servlet or jsp under some of web containers (tomcat).Then You will have that HttpServletRequest initialized in get or post method.
_Dima_a at 2007-7-8 22:44:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Thanks...I appreciate the help!
moy021a at 2007-7-8 22:44:40 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...