aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes 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 ""pageContext.include"" Watch ""pageContext.include"" New topic
Author

"pageContext.include"

Kosala W.Abayagunawardene
Ranch Hand

Joined: Dec 15, 2007
Posts: 47

I found this question on Javabeat..could not understand what "pageContext.include" means.need some explanation.Thanks(answers are a,b,d)

Assuming that a JSP by name "one.jsp" wants to have a request time inclusion
to happen for the page "two.jsp". Choose the following right operations (assuming
that the following code is residing in "one.jsp"?

a. pageContext.include("two.jsp")
b. <jsp:include page = "two.jsp" />
c. <@% include file "two.jsp" %>
d. request.getRequestDispatcher("two.jsp").include(request, response)
e. All the above.


[SCJP] ::[SCWCD]::[BCS::BIT::SCBCD] - Studying[My Blog]
Pete Pommelich
Greenhorn

Joined: Oct 14, 2009
Posts: 6
Hi,

calling include method of the PageContext has the same effect -as the answerd indicate- as calling the include method of the RequestDispatcher or using the jsp:include action. From the API
Causes the resource specified to be processed as part of the current ServletRequest and ServletResponse being processed by the calling Thread. The output of the target resources processing of the request is written directly to the ServletResponse output stream.

The current JspWriter "out" for this JSP is flushed as a side-effect of this call, prior to processing the include.

If the relativeUrlPath begins with a "/" then the URL specified is calculated relative to the DOCROOT of the ServletContext for this JSP. If the path does not begin with a "/" then the URL specified is calculated relative to the URL of the request that was mapped to the calling JSP.


And pageContext is a implicit object available in a JSP.

Correct me if I'm wrong.

Kind regards,
Mike Mitchell
Ranch Hand

Joined: May 28, 2008
Posts: 37
Looking into this, I got an unexpected result for the RequestDispatcher include method. Please see screenshot and code below. Does it make sense the file included via RequestDispatcher seems to appear always at the top, and not where it was placed in the including page? Has this something to do with flushing out? I checked the entry for RequestDispatcher.include() in the 1.4 api and didn't notice a clue about that. Hope I haven't missed something obvious or done something careless.

Thanks,
Miike









SCJP 5, SCWCD 5
Paul Tokmakov
Greenhorn

Joined: Oct 26, 2009
Posts: 3
That's because RequestDispatcher sends included content directly to the response stream, ignoring jsp's output buffer, so included content will always appear at the begining of the stream i.e. on top of the page. That's why we need "pageContext.include" which uses the buffer.
Mike Mitchell
Ranch Hand

Joined: May 28, 2008
Posts: 37
Thanks Paul!
Nabila Mohammad
Ranch Hand

Joined: Nov 05, 2007
Posts: 661
What's the difference between Response Stream and Buffer.I thought the response is written on to the buffer
It's getting confusing!


The future belongs to those who believe in the beauty of their dreams.Dream BIG!
Paul Tokmakov
Greenhorn

Joined: Oct 26, 2009
Posts: 3
As far as I understand it, jsp has it's own response stream with buffer (of type JspWriter) on top of the one we get from response.getWriter().
By the way, you can check this by setting In this case content included with RequestDispatcher will appear in the right place, because all otput from jsp will be automatically flushed to the actual response strean.
Kosala W.Abayagunawardene
Ranch Hand

Joined: Dec 15, 2007
Posts: 47

Thanks guys you been big help.keep up the good work
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: "pageContext.include"
 
Similar Threads
Diff between IncludeAction & ForwardAction
Problem with forward and include JSP tag
jsp:getProperty calling bean from specific scope
Calling one JSP from another JSP
problem using getSession(boolean create)