• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

object with page scope

 
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are object of page scope accessible to the included JSP page?
thanks.
[ June 05, 2002: Message edited by: Jerson Chua ]
 
Ranch Hand
Posts: 1011
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Jerson Chua,
This is really a tricky question, but a good question!
The anwser is:
YES, if you use include directive;
NO, if you use jsp:include.
example:
in a Java class, you have:
==========================
package anypackage;
public class MyBean {
private message = null;
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
}
in test1.jsp, you have the code:
================================
<jsp:useBean
id="myBean"
class="anypackage.MyBean"
scope="page"/>
<jsp:setProperty
name="myBean"
property="message"
value="HelloWorld"/>
<%@include file="/test2.jsp"%>
in test2.jsp, you have the code:
================================
<jsp:getProperty
name="myBean"
property="message"/>
if you call test.jsp, you will have no problem and get an output of "HelloWorld". Because the test2.jsp was included at the page-translation time, so the jsp implimentation object has already combined these two jsp pages. You are actually calling one servlet.
Now, if you change the include directive in test.jsp to:
<jsp:include page="/test2.jsp"/>
Now call test.jsp, you will get an error, something like: "Attempted a bean operation on a null object".
In this case, the test2.jsp was included at the request time, and you are actually calling two jsp implemetation objects, while the second (included) implementation object can not see the object defined in the first implementation object.

Hope this helps.
 
Jerson Chua
Ranch Hand
Posts: 68
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thank you very much.
Just curious Tony, have you passed the exam? if not, how long have you been preparing for the exam?
 
Tong Chen
Ranch Hand
Posts: 1011
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My pleasure, Jerson.
Actually I am ready to take the exam and will do it very soon, maybe next week.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic