Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP usebean, getproperty, setproperty and scopes

 
Yasir Bajwa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am reading Head First Servlets and JSP ... and a bit lost with the jsp:useBean, jsp:setProperty, and jsp:getProperty.

I know the default scope is "page", but if the attribute is not found in that scope, will the container generate code to search the other scopes (request, session, application).

The exercise answers on pg. 356 would appear to indicate this .. although I didn't find it mentioned anywhere in the text, and it doesn't quite make sense to me that useBean would search other scopes before creating the attribute in the page scope.


Thank you for your help!

P.S. This is my first post, is there a forum for this particular textbook? I could not find it.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65542
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Yasir Bajwa:
I know the default scope is "page", but if the attribute is not found in that scope, will the container generate code to search the other scopes (request, session, application).


Sort of. It will search the other scopes, but it doesn;t need to generate any code to do it. It will use the services of the PageContext.findAttribute() method which will search in all scopes.

it doesn't quite make sense to me that useBean would search other scopes before creating the attribute in the page scope.


Why not, that way you don't need to specify a scope to have all scopes searched. if that's not what you want, explicitly set page scope.

P.S. This is my first post, is there a forum for this particular textbook? I could not find it.


Not formally, but it's discussed a great deal in the SCWCD forum.
 
Yasir Bajwa
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you so much for the fast reply!

Ok, I think I got it now. I thought that leaving the scope out was exactly the same as specifying it as "page". So if I understand correctly, explicitly specifying a scope limits you to only that scope, while leaving it implicit means search each scope (page, request, session, application)?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65542
110
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's correct, at least for <jsp:useBean>. Different actions may have different semantics. It's best to always check the documentation. Grab a copy of the JSP Specification and keep it handy.
 
And will you succeed? Yes you will indeed! (98 and 3/4 % guaranteed) - Seuss. tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!