This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes setting cookies on client machine Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "setting cookies on client machine " Watch "setting cookies on client machine " New topic
Author

setting cookies on client machine

sony rao
Greenhorn

Joined: Jun 18, 2007
Posts: 20
hello

i need to set cookies on the client machine say for example in C:\Documents and Settings\users\Cookies. how do i do it with the help of servlets. can anyone please guide me. iam completely lost. thanks in advance.
Arvind Kamath
Greenhorn

Joined: Jul 17, 2007
Posts: 3
Hi,
Please check the below link this may help you out.
http://www.dickbaldwin.com/java/Java693.htm



Regards,
Aravind
Amit Kumargupta
Ranch Hand

Joined: Apr 13, 2007
Posts: 54
I think this will be helpful.

public String getPath()
public void setPath(String path)

These methods get or set the path to which the cookie applies. If you don�t specify a path, the browser returns the cookie only to URLs in or below the directory containing the page that sent the cookie. For example, if the server sent the cookie from http://ecommerce.site.com/toys/specials.html, the browser would send the cookie back when connecting to http://ecommerce.site.com/toys/bikes/beginners.html, but not to http://ecommerce.site.com/cds/classical.html. The setPath method can be used to specify something more general. For example, someCookie.setPath("/") specifies that all pages on the server should receive the cookie. The path specified must include the current page; that is, you may specify a more general path than the default, but not a more specific one. So, for example, a servlet at http://host/store/cust-service/request could specify a path of /store/ (since /store/ includes /store/cust-service/) but not a path of /store/cust-service/returns/ (since this directory does not include /store/cust-service/).
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Originally posted by sony rao:
hello

i need to set cookies on the client machine say for example in C:\Documents and Settings\users\Cookies. how do i do it with the help of servlets. can anyone please guide me. iam completely lost. thanks in advance.


I do not think that we can specify the location where the cookie need to be saved.Using servlet api you can create cookie and send to client , but again you cannot specify any location.


Rahul Bhattacharjee
LinkedIn - Blog
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41124
    
  45
In addition to what Rahul said, cookies are browser-specific, and each browser stores cookies in a different location. The web app has no control over that.

The setPath method mentioned above refers to server paths, not client paths.


Ping & DNS - my free Android networking tools app
Amit Kumargupta
Ranch Hand

Joined: Apr 13, 2007
Posts: 54
so is there any way to find the location of cookies in client side
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

No, and you shouldn't need to.
Why would need to know where files are on a client's machine?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Ashok Mor
Ranch Hand

Joined: Jul 17, 2007
Posts: 44
Amit, There are diff diff root folder for each user of the system, so there will be separate 'cookie' folder creadted inside root folder of each user, so in these cookie folder there will be index.dat file. so all cookie information will be stored in this file.






Ashok Mor
Ness Technology, Bangalore.
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
It depends on the client/browser.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: setting cookies on client machine
 
Similar Threads
HttpSession
cookies usage
opening two tabs
Retrieving Cookies
We are into serious Cookie business- HFSJ and Cookies