• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Cookies

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello everyone,
Speaking of cookies...
Does anyone know of a routine that lets you add and retrieve a cookie that holds more than one name/value pair. I wrote stringIt and unstringIt methods to name a cookie and for the value use instead a list of N/Vs in this format name:value|name:value| etc etc
I probably am reinventing the wheel here but I could not find an example anywhere to use just one cookie. I know how to do it in javascript but has anyone done it in java?
Thanks.
 
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can add your name/value pairs to a collection, anad then put your collection in a cookie.

Bosun
 
Bosun Bello
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Regarding my previous post, since the name/value of a cookie must be strings, you may have to resort to using the HttpSession interface.

Bosun
 
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bosun, do you mean "don't use cookies, use the session object"? or something else?

 
Bosun Bello
Ranch Hand
Posts: 1514
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, Mike that's what I meant. My thinking is that what he is trying to achieve might be easier by using a session object instead of cookies. Since he can add his name/value pairs to a hashMap or so, and then store it in the session.

Bosun

 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hmm.. boys named Mary. What's it coming to?



But how about that? If you want to persist it beyond a session, you need to use a cookie. And the Cookie class only takes String values.

The only way I see is to do as Mary has done, ie: Make your own 'markup' within a string that allows you to delimit multiple values.
 
Mary Cushing
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you, Bosun and Mike, for your comments.
I am new to java and was trying to figure out if one the collection objects has methods that I can use. Rather than doing it myself, I use a two dimensional array, BTW. Do any of them have methods that 'translate' them to a string or in the reverse, take a string and convert it to a collection. This would make it easier for me to do multiple cookies. (I do need them to persist.) I was hoping for something like javascript's split method or some other method that takes delimited string and converts it to an array or other collection that I can manipulate easily.
I hope you understand what I getting at.
 
Mike Curwen
Ranch Hand
Posts: 3695
IntelliJ IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can look at StringTokenizer class. It's in the java.util package. The Tokenizer will take a String in it's constructor and has a few methods that will return each 'token' of that String.

What determines the delimiter of your tokens is either the defaults (space, tab, newline, return and form feed), or the second String you send to the Tokenizer constructor.

You would use this class for very simple, custom-made Strings of values. (like you have with the colons and such).

All objects in Java have a method they inherit from the Object class... it's called toString(). Most default implementations of this method will provide something like a hex value and it's pretty useless. But others provide useful toString()'s... for example, a HashMap's toString() will return a nicely formatted string of the form... "{name=value[,name=value]}"
[This message has been edited by Mike Curwen (edited October 28, 2001).]
reply
    Bookmark Topic Watch Topic
  • New Topic