I am not clear with the explanation given for Q12(page 461) in SCWCD kit. Question is Consider the following code contained in a file named this.jsp <jsp:useBean id="address" class="AddressBean" /> <jsp:setProperty name="address" property="*" /> <%@ include file="that.jsp" %> Which of the following is true about the AddressBean instance declared in the above code a) The bean instance will not be available in that.jsp. b) The bean instance may or may not be available in that.jsp, depending on the threading model implemented by that.jsp. c) The bean instance will be available in that.jsp, and the that.jsp page can print the values of the bean�s properties using <jsp:getProperty />. d) The bean instance will be available in that.jsp, and the that.jsp page can print the values of the bean�s properties using <jsp:getProperty /> only if that.jsp also contains a <jsp:useBean/> declaration identical to the one in this.jsp and before using <jsp:getProperty/>. As per my understanding Answer should be option (a). bcoz we have included that.jsp in this.jsp so the bean instance will not be avialable in that.jsp. But Answer given is (c) and explanation given is The that.jsp page is included using a directive. Thus, it is a static inclusion, and the two pages form a single translation unit. I dont understand this. How come we can have the instance of bean avialable in that.jsp file? Scope of bean is page so it wld be avialabe only in this.jsp page and moreover this.jsp has included the that.jsp so for the translation of this.jsp that.jsp is required and that.jsp will always get executed independently. I tried the example and ran that.jsp page i got null pointer exception. can anybody shed some light on this? thanks -MOhit
Hi Mike Still i am not clear.. If its true then why did i get null pointer exception when i ran that.jsp. And second thing in static inclusion, jsp engine writes the content of included file into including file and treat the included file seprately. Thats why in static inclusion even if you change the content of included file and run the jsp page which has included this file will not reflect the changes. -MOhit
Hi Mohit, I admit that this code is very bad style for the real life. Of course this case is intended for exam only, not for real life. The that.jsp will never run separetely well, because it doesn't make the instance of bean (by call <jsp:usebean ... />, so then if we run separately this code by calling <jsp:getProperty ... />, we will get null error (no instance / object reference). I think this question just trying our understanding about static inclusion.
I agree with you that either ans a) or c) is the true choice. But in this case, the context of question is about static inclusion by using "include directive". I think the question is very tricky, so we should choose the best answer regarding the context.
and POOF! You're gone! But look, this tiny ad is still here:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth