This week's book giveaway is in the Java 8 forum.
We're giving away four copies of Java 8 in Action and have Raoul-Gabriel Urma, Mario Fusco, and Alan Mycroft 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 | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
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: 60082
    
  65

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: 60082
    
  65

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://aspose.com/file-tools
 
subject: JavaBean Scope in JSP pages
 
Similar Threads
DD Tag Order
Reading int headers from a Servlet
Problem in Mapping Composite Primary Key with Hibernate
Servlet representation in a UML diagram
JSF Warnings