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

Doubt in EL Implicit Objects: Cookie

 
sakthikumaran navakumar
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
  • 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.
 
James Mark
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it is value
 
Atul Sawant
Ranch Hand
Posts: 304
  • Mark post as helpful
  • send pies
  • 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.
 
Jayant Raj
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is 'value' & the same has been confirmed in HFSJ errata page.
 
Michael Ku
Ranch Hand
Posts: 510
  • Mark post as helpful
  • send pies
  • 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
 
Ken Truitt
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • 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
  • 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
 
Marc Peabody
pie sneak
Sheriff
Posts: 4727
Mac Ruby VI Editor
  • Mark post as helpful
  • send pies
  • 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"]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic