Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question about pageContext Attributes

 
Ravi Singh
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Consider the contents of two JSP files:
File 1: test1.jsp
<html><body>
<% pageContext.setAttribute("ninetyNine", new Integer(99)); %>
//1
</body></html>
File 2: test2.jsp
The number is <%= pageContext.getAttribute("ninetyNine") %>
Licensed to Tricia Fu <tricia.fu@gmail.com>
234 CHAPTER 12 REUSABLE WEB COMPONENTS
Which of the following, when placed at line //1 in the test1.jsp file, will
allow the test2.jsp file to print the value of the attribute when test1.jsp
is requested? (Select one)
a <jsp:include page="test2.jsp" />
b <jsp:forward page="test2.jsp" />
c <%@ include file="test2.jsp" %>
d None of the above because objects placed in pageContext have the page
scope and cannot be shared with other components.



Can anyone answer the above question
 
Jan Sterk
Ranch Hand
Posts: 142
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a good question!

I think c, because the include directive has the same effect as copy/pasting.

Apparently a is false. With the jsp:include action, a method-call is placed in jps1. That method does a RequestDispatcher.include() to jsp2 kind of thing. It has the request and response object as parameters, but not the pageContext object from jsp1.
 
Amit Prakash Singh
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Option "C" is correct as Jan said it has the same effect as copy and paste the included file.

Option "a" is incorrect because a request will be dispatched to 2nd jsp and its response will be included here and pageContext of 2nd Jsp is different than the 1st Jsp.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic