This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes web components certification question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "web components certification question" Watch "web components certification question" New topic
Author

web components certification question

galina bloch
Greenhorn

Joined: Oct 30, 2006
Posts: 11
What modifications should be made in test.jsp to make the employee bean accessible within another jsp.
test.jsp
<jsp:useBean ud="employee" class="EmployeeBean"/>
<jsp:include page="another.page"/>
another.jsp
<jsp:getProperty name="employee" property="salary"/>

Correct answer is: modify the code to use the include directive instead of include action.
Explanation is: By default the scope of the bean is page, so the bean will not be available when the include directive is used. Why?
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

Please QuoteYourSources.


[My Blog]
All roads lead to JavaRanch
Nilesh Miskin
Ranch Hand

Joined: Jun 17, 2010
Posts: 44
There is a difference in the way the include directive & <jsp:include> standard action work. Include directive actually includes the source of the included file while <jsp:include> standard action includes the response of the included page. You can have a look at the container generated servlets for the JSPs implementing both these options for a deeper understanding.


Nilesh Miskin
galina bloch
Greenhorn

Joined: Oct 30, 2006
Posts: 11
I thought it has something to do with the page scope.
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

galina bloch wrote:I thought it has something to do with the page scope.

Please QuoteYourSources.
Ankit Garg
Sheriff

Joined: Aug 03, 2008
Posts: 9303
    
  17

galina don't ignore Christophe's request to quoting source of the question. Mentioning the source of mock exam questions is mandatory at javaranch...


SCJP 6 | SCWCD 5 | Javaranch SCJP FAQ | SCWCD Links
galina bloch
Greenhorn

Joined: Oct 30, 2006
Posts: 11
source: whizlabs mock test
Michael Angstadt
Ranch Hand

Joined: Jun 17, 2009
Posts: 273

Like Nilesh said, the two include techniques are different. The include directive puts the contents of the included page directly inside of the JSP when it is translated into Java code and compiled. This means that if the included page contains dynamic content, it will never change (because it was evaluated only once). The include standard action includes the page every single time so that dynamic content shows up. So the include directive is better for static content and the include standard action is better for dynamic content.

Because the include directive puts the contents of the file directly inside of the JSP, you can use page scope.

index.jsp:
another.page.jsp:


But if using the include standard action, you must use request scope because the included page exists in a separate page scope.

index.jsp:
another.page.jsp:


I hope that helps you..


SCJP 6 || SCWCD 5
 
GeeCON Prague 2014
 
subject: web components certification question