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

Q63 HFSJ mock exam

 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In this question they have given a complete jsp and asked to find out which lines generate errors?

There is a JSTL tag used without taglib directive that is wrong I agree
But there is a jsp:setProperty usage without a previously declared jsp:useBean tag.This is not listed in the error any specific reason why?
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can anyone please help me with this?IS the usage of js:setPropert or jsp:getProperty without a previously declared jsp:useBean valid?
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this is perfectly valid. I don't know how. But I read this from David Bridgewater's book. Here it is as below,

Actually, the truth is that you can use <jsp:setProperty> and jsp:getProperty> without a previous <jsp:useBean>. All <jsp:setProperty> and <jsp:getProperty> do is to use PageContext.findAttribute()�so if an attribute of the right name exists�set up, perhaps, in a previous servlet�these standard actions will fi nd it. However, it�s good practice to
include <jsp:useBean> before these actions in the same JSP page. After all,
it won�t replace beans of the same name that you have set up by other means,
and it will create beans of the right name that don�t exist already. Furthermore, if your <jsp:setProperty> and <jsp:getProperty> standard actions try to access an attribute that doesn�t exist, they are liable to die a horrible death with HTTP 500 errors returned to the requester.
 
Renu Radhika
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But HFSJ says there is a default scope for setProperty and getProperty.But from your explanation it looks in all the four scopes.So which is right?
 
Joe Harry
Ranch Hand
Posts: 10128
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It looks in all the 4 scopes and when it finds a match it returns a value. That's it. If there is no match nothing is returned. The truth here is, you can use jsp:setProperty without a jsp:useBean. Try it for yourself!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic