• 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

getting cookies with EL

 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
why do we have to use .value like ${cookie.userName.value} ?
why can't we use just ${cookie.userName}?
whats the difference?
 
Sheriff
Posts: 14691
16
Eclipse IDE VI Editor Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The cookie implict object is a Map of Cookie objects. So userName will refer to a Cookie instance. How do you retrieve the value of a cookie instance ?
 
maih fhil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mean to say cookie a Map with keys as name of the cookie and the value as the cookie object
In that case consider the folllowing code:

web.xml

[and


How come now we can get the value for mainEmail without using .value
 
pie sneak
Posts: 4727
Mac VI Editor Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by maih fhil:
How come now we can get the value for mainEmail without using .value


EL sees that initParam is a map and so the method it calls is something like initParam.get("name"), which returns the value in the map that is associated with the key of "name".

OK, OK, I know this seems to contradict what's happening with Cookies. The Cookie map is a little different though. The initParam map is a <String, String> while the cookie map is a <String, Cookie>. That means the cookie map returns you a Cookie object.

Check out the Cookie API. Note that it has a method called getValue() that returns the internal String value. The .value in your EL calls this method so what gets displayed in the browser is the value of the Cookie. Otherwise, my guess is you'll get a weird Cookie object reference printed out like Cookie@abracadabra which wouldn't be terribly helpful.
[ November 30, 2007: Message edited by: Marc Peabody ]
 
maih fhil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks a lot
I was quite confused over this
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic