File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes Setting Cookie Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Setting Cookie" Watch "Setting Cookie" New topic

Setting Cookie

Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 761
I have created a small application to create and set cookie. My servlet code is bellow.

can anybody tell me what will this code do ?
and if it is creating cookie than where can i see my cookie ?
what will be the default location of my cookie ?
how cn i set the cookie location ?
I want to set the cookie at client end.

Jigar Naik

Shu Gao

Joined: Aug 01, 2005
Posts: 18
This code creates a cookie named 'param1', and map its value to whatever the value of the query parameter 'param1' is, and its expiry value is 1800 seconds.

developers don't need to worry about the location, the cookie is by default stored on client-end, where the location is where your browser store your temporary internet files.

Hope that helps.

SCJP 1.4<br />SCJD<br />SCWCD 1.4
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 761
but how do i retrive the name value pairs stored in the cookie ?
Jigar Naik
Ranch Hand

Joined: Dec 12, 2006
Posts: 761
and what does this function doing

I had written it to know the location of cookie at client end.
Muhammad Saifuddin
Ranch Hand

Joined: Dec 06, 2005
Posts: 1323

Originally posted by Jigar Naik:
and what does this function doing

Java Doc would be your first place to know about it..Cookie.getPath
[ January 08, 2007: Message edited by: Saif uddin ]

[Blog][Linkedin] How To Ask Questions On JavaRanch My OpenSource
santhoshkumar samala
Ranch Hand

Joined: Nov 12, 2003
Posts: 156

you can get name value pairs by using following code

loop through cookies array using a for or while loop

santhosh<br />SCJP,SCWCD
It is sorta covered in the JavaRanch Style Guide.
subject: Setting Cookie
It's not a secret anymore!