Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

getting cookies with EL

 
maih fhil
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • 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?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • Quote
  • Report post to moderator
thanks a lot
I was quite confused over this
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic