• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

include

 
Ranch Hand
Posts: 66
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the difference between
<% pageContext.include("a.jsp"); %> and
<jsp:include page = "a.jsp" />
 
Ranch Hand
Posts: 185
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 10198
3
Mac PPC Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'm coming across <% pageContext.include(String Url); %> for the first time!
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
reply
    Bookmark Topic Watch Topic
  • New Topic