Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Doubt in EL Implicit Objects: Cookie

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

In HFSJ Page No : 388 they have dealt about the implicit EL object cookie


<%Cookie cookies = request.getKookies();

for(int i = 0; i<=cookies.length; i++){
if((cookies[i].getName()).equals("userName")){
out.println(request.getValue());
}
}%<

EL representation given in Book : ${cookie.userName.valu}

Whether thevalu is the sytem in built keyword?

Can you please tell me whether the equaivalent [] representation for the above is given JSP code scriptlet is $cookie["userName"]["valu"]}

If am wrong please tell me the equivalent.

Thanks and Regards,

Sakthi.
 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think it is value
 
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please go and check API of cookie in javax.servlet.http package

http://java.sun.com/j2ee/1.4/docs/api/index.html

the class Cookie has some important methods...

getName
getValue
setMaxAge
getPath

etc...


considering the example given above..

when you say ${cookie.username.value} it means

cookies[i].getUsername.getValue

Please read standards of how Bean class should be coded and how exactly they are read.
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is 'value' & the same has been confirmed in HFSJ errata page.
 
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just passed the SCWCD exam and used HFJS. It had a lot of errors.

If you are relying on the HFSJ book, then you should first get the errata from the website and manually make the corrections to the text. If you do not, you could wind up missing some questions that you otherwise would get right. This is what I did and it helped a lot
 
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
if the proper way to access a cookie's value in el is
${cookie.username.value}
then this assumes that the cookie object works like a bean,
with the naming conventions and all. That is, the cookie
object referenced by ${cookie.username} from the cookie map
which is the implicit object. I don't know that this was ever
said directly in hf.... Why would one assume this is so?

Ken
 
Ken Truitt
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Also, if it is true that anything you can do with the dot-operator you can do with the collection operator, is the equivalent of
${cookie.username.value}
as expressed with the '[]' operator,
${cookie[username][value]}?

Ken Truitt
 
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

if the proper way to access a cookie's value in el is
${cookie.username.value}
then this assumes that the cookie object works like a bean,
with the naming conventions and all. That is, the cookie
object referenced by ${cookie.username} from the cookie map
which is the implicit object. I don't know that this was ever
said directly in hf.... Why would one assume this is so?


ANY object with a proper get method can have that get method accessed like a bean in EL. Since Cookie has a getValue method, it can be called in EL with .value tacked on.


Also, if it is true that anything you can do with the dot-operator you can do with the collection operator, is the equivalent of
${cookie.username.value}
as expressed with the '[]' operator,
${cookie[username][value]}?


Almost. You forgot to add quotes inside the []s.
${cookie["username"]["value"]
 
Well behaved women rarely make history - Eleanor Roosevelt. tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic