Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

A question about cookies

  Asked By: Ludwig    Date: Jun 02    Category: Java    Views: 543
  

I have a question. Is it possible that we read cookies on a local machine without using HttpServlet class and it's methods? How? I want just to read cookies in my local machine and I haven't any Http request, actually in a usual Java class that is not a servlet, I want to read cookies of my machine, is it possible? How?

Share: 

 

3 Answers Found

 
Answer #1    Answered By: Andrew Brown     Answered On: Jun 02

You can read  your local  machine cookies  use client side scripting. maybe this method useful for you :


function getCookie(c_name)
{
if (document.cookie.length>0)
{
c_start=document.cookie.indexOf(c_name + "=")
if (c_start!=-1)
{
c_start=c_start + c_name.length+1
c_end=document.cookie.indexOf(";",c_start)
if (c_end==-1) c_end=document.cookie.length
return unescape(document.cookie.substring(c_start,c_end))
}
}
return ""
}

 
Answer #2    Answered By: Gustavo Costa     Answered On: Jun 02

Please note that cookies  are nothing but plain text files. As long as location of a file is known then you can use java.io.* package to read  contents of that file.

I was wondering why you want to do that?

 
Answer #3    Answered By: Tommy Thompson     Answered On: Jun 02

for example in IE cookies  are stored in files go to
Tools --> Internet Options --> Settings --> View Files
then search for txt files that begin with name cookie
they are generally named like cookie:user@site
you can open them just like any file,

in firefox it is a little harder because all cookies are stored in one file. and I don't know its format :-)
but I guess you can download the source and find the format your self :-)

 
Didn't find what you were looking for? Find more on A question about cookies Or get search suggestion and latest updates.




Tagged: