This week's book giveaway is in the Agile and other Processes forum.
We're giving away four copies of The Mikado Method and have Ola Ellnestam and Daniel Brolund on-line!
See this thread for details.
The moose likes JSP and the fly likes JavaBean Scope in JSP pages Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » JSP
Reply 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: 56179
    
  13

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 ]

[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56179
    
  13

P.S. Confusing semantics such as this is just one of the many reasons that scriplets are discouraged in the JSP 2.0 environment.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: JavaBean Scope in JSP pages
 
Similar Threads
Servlet representation in a UML diagram
JSF Warnings
Reading int headers from a Servlet
DD Tag Order
Problem in Mapping Composite Primary Key with Hibernate