• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

include

 
uday ogra
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between
<% pageContext.include("a.jsp"); %> and
<jsp:include page = "a.jsp" />
 
nitin pai
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 185
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 66
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10112
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm coming across <% pageContext.include(String Url); %> for the first time!
 
uday ogr
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
@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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic