Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaBean Scope in JSP pages

 
Reema Patel
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a bit confused as to why the following code snippet is compiling and working.




The bean reference "store" is local to the if block. This should have resulted in a compilation error. Instead, everything works just fine. I'm using Tomcat 5.


- Reema
[ December 16, 2006: Message edited by: Reema Patel ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Reema Patel:

The bean reference "store" is local to the if block.


Not.

The scripting variable created by the useBean action is indeed limited to the block. But that's not what you are referencing in the getProperty action. That is referencing the scoped variable created by useBean. And that has page scope.
[ December 16, 2006: Message edited by: Bear Bibeault ]
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64838
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
P.S. Confusing semantics such as this is just one of the many reasons that scriplets are discouraged in the JSP 2.0 environment.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic