• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Applet cookie access and retrieval

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have an applet and I am testing some slightly modified code from the documentation (at http://java.sun.com/docs/books/tutorial/deployment/doingMoreWithRIA/accessingCookies.html). The plan is to set a cookie and retrieve all cookies for the URL. Then it prints them out.

Unfortunately, as far as I can tell the cookie is not being added. When I print 'cookieJar.getCookie()' immediately after the add method its there, but when I run the code a second time, it does not print out any cookies in the first half of the code. It appears to print out cookies for http://www.sun.com, which is why I think it is not adding.

Basically I want it to add a cookie which I can retrieve later, but I cannot seem to add the cookie. Does anyone know how I can do this?

I have my policy file set as 'permission java.security.AllPermission;'. I am running this in appletviewer at the moment. This method uses the java.net package for cookies as opposed to the netscape package to control javascript. I figured it would be easier to use an existing package than download another one. The code is below.



Thanks for any help.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to JavaRanch.

I've never used any of the involved classes, but from my reading of the javadocs it sounds like "new CookieManager()" stores cookies in-memory, i.e., in a transient fashion. Try the other CookieManager constructor which supplies a CookieStore.
 
Greg Davies
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you're implying that I need to create a new class to implement the CookieStore interface. I'll give that a try.

Before I do that though, I had an idea. Is there the possibility that appletviewer does not have the same cookie-handling capabilities as a browser? The reason I ask is that's where the applet is running at the moment.

Furthermore, do I need to work out how to store cookies somewhere client-side from within the cookie-storing object? If so I still need to work out how to do that. In the meantime I'll try using a map or something. I'll post my findings here.

Thanks
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Is there the possibility that appletviewer does not have the same cookie-handling capabilities as a browser? The reason I ask is that's where the applet is running at the moment.


I'm fairly certain that appletviewer does not store cookies persistently (I'm not actually sure if it stores cookies even temporarily in memory...)
 
Greg Davies
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I'm fairly certain that appletviewer does not store cookies persistently (I'm not actually sure if it stores cookies even temporarily in memory...)



I'll probably put cookie experiments on hold until I set up an efficient way to test applets in a browser. A subject for another thread perhaps .
 
There were millions of the little blood suckers. But thanks to this tiny ad, I wasn't bitten once.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic