• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

web components certification question

 
galina bloch
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please QuoteYourSources.
 
Nilesh Miskin
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
galina bloch
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought it has something to do with the page scope.
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
galina bloch wrote:I thought it has something to do with the page scope.

Please QuoteYourSources.
 
Ankit Garg
Sheriff
Posts: 9577
33
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
galina don't ignore Christophe's request to quoting source of the question. Mentioning the source of mock exam questions is mandatory at javaranch...
 
galina bloch
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
source: whizlabs mock test
 
Michael Angstadt
Ranch Hand
Posts: 277
Eclipse IDE Java PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic