Not setting cookie
Posted on 2000-05-15
First of all I am very much new to Java itself.
I have one login form which has 2 fields for username and password.
Now first of all how do you set cookie on clients m/c.
I have to also pass username and password entered by user to that cookie for storing.
Please do give me some sample code(small one if possible)
I have seen some code for setting cookie but passing username and password from .jhtml page(jhtml since using ATG Dynamo) to cookie.
here is my small code also which I have written
PrintWriter outpage = response.getWriter();
javax.servlet.http.HttpSession hs = request.getSession(true);
String sessid= new String(hs.getId());
Cookie cookie = new Cookie("username","arpit");
Cookie cookies = request.getCookies();
outpage.println("getpath = "+cookies[i].getPath());
outpage.println("getvalue = "+cookies[i].getValue());
Here it is not setting the cookie also.
i.e. I cannot find any text file with word "username" etc.......
what does this getvalue and putvalue do and what is the parameters it accept.
Say if I pass the username from my form in a variable named "abc" then how can I use putvalue?
I would like to know that say once if u have set the cookie how do you retrieve it means first of all how do I set a cookie with some name say "xyz" and then retrieve it, if it is set.
I am bit confused about this.
Please tell me methods to use for:
1)to set a cookie alongwith passing username and password from form,if cookie is not set.
2)if it is set how to retrieve it and get the username and password from it.
Please make it fast.
I just need the method names to be used for particular functionality.
One more problem is ,that I can't find the text file in which the cookie is set
what about that?