GeeCON Prague 2014*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes include 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 "include" Watch "include" New topic
Author

include

uday ogra
Ranch Hand

Joined: Jul 03, 2007
Posts: 66
What is the difference between
<% pageContext.include("a.jsp"); %> and
<jsp:include page = "a.jsp" />


People laugh at me just because i am different and i laugh on them just because they all are same.That's ATTITUDE<br /> <br />IBM DB2 8.1<br />SCJP 1.4<br />SCWCD 1.4<br />Oracle 9i-007<br />IBM XML 142<br />SCJA<br />SCBCD5<br />SCDJWS<br />IBM Websphere MQ 994<br />IBM SOA 664
nitin pai
Ranch Hand

Joined: May 30, 2006
Posts: 185
In my opinion pageContext.include() is a convineance method for doing:

RequestDispatcher rd = servletContext.getRequestDispatcher("/../..");
rd.include(request,response);

Hence it would be the same as:
<jsp:include page="/../.."/>

[ July 07, 2007: Message edited by: nitin pai ]
[ July 07, 2007: Message edited by: nitin pai ]


nitin pai
Ranch Hand

Joined: May 30, 2006
Posts: 185
just ignore my earlier answer.

I felt that <jsp:include> was translated to a servletcontext dispatching mechanism. But when I saw the generated servlet the <jsp:include> generates the following code:

<jsp:include page="nothing.jsp"/>

was converted to:

org.apache.jasper.runtime.JspRuntimeLibrary.include(request, response, "nothing.jsp", out, false);
uday ogra
Ranch Hand

Joined: Jul 03, 2007
Posts: 66
ok
I think I know 1 minor diffrence.
pagecontext.include() always flushes the output of the current page while

jsp:include flushes it only if flush is explicitly set to true.
Kamal Agrawal
Greenhorn

Joined: May 25, 2007
Posts: 14
Basically there are three include methods:

1. <% pageContext.include(String Url); %>
2. <jsp:include page="URL"/>
3. <%@ include file="Url" %>

The first one allows you to specify a variable url in your JSP, whereas last two need a literal (hardcoded) String as the URL.

Another difference is that The last one i.e. include directive lets you include files at the time the JSP page is translated into a servlet. They actually become part of the generated servlet code. Changing the file that is included won't have an effect until the jsp is modified and recompiled. Whereas the first two include the file at execution time so modifications to the included file will be noticed the next time the page is executed.

Please add your comments.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9396
    
    2

I'm coming across <% pageContext.include(String Url); %> for the first time!


SCJP 1.4, SCWCD 1.4 - Hints for you, Certified Scrum Master
Did a rm -R / to find out that I lost my entire Linux installation!
uday ogr
Greenhorn

Joined: Jul 09, 2007
Posts: 3
@kamal

I would like to second you on that.In jsp:include you can provide variable URI.As far as i know you can provide request time values for dynamic inclusion but you cant do so in case of static inclusion.
So i think the point i mentioned is perhaps the only difference between pagecontext.include and jsp:include.But may be i am wrong.
 
GeeCON Prague 2014
 
subject: include