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.