GeeCON Prague 2014*
The moose likes JSP and the fly likes JavaBean Scope in JSP pages Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » JSP
Bookmark "JavaBean Scope in JSP pages" Watch "JavaBean Scope in JSP pages" New topic
Author

JavaBean Scope in JSP pages

Reema Patel
Ranch Hand

Joined: Jan 26, 2006
Posts: 169
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

Joined: Jan 10, 2002
Posts: 61315
    
  66

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 ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

P.S. Confusing semantics such as this is just one of the many reasons that scriplets are discouraged in the JSP 2.0 environment.
 
GeeCON Prague 2014
 
subject: JavaBean Scope in JSP pages