• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

what's the # btw include , pageContext.include and jsp:include

 
Reda Mokrane
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between the of <%@ include file="relative url" %> , <% pageContext.include(String relativeUrlPath); %> and
<jsp:include page="relative URL" flush="true" />
Thanks
 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Reda,
the <%@ include file="relative url" %> is a jsp-directive.
It takes action at translation time of jsp -> servlet by the jsp engine.
(Translation time means: The jsp engine creates a servlet from the jsp and compiles it, when it was first invoked or on startup of server, if you set some parameters in web.xml. If u use Tomcat you find this servlet in a subirectory of the directory named "work" of your Tomcat-Server.)

The <jsp:include page="relative URL" flush="true" /> is a jsp-action tag. It takes action at request-time. You can pass parameters to the included page:

Of course, you cant do that with the directive-included file. It makes no sense because at translation time you have no user input.
Its quite instructive to see what the jsp - engine of tomcat actually generates out of the jsp. An example for a include directive you can find in the include example (http://localhost:8080/examples/jsp/include/include.jsp) of tomcat (just search in the work directory for the generated servlet). Here are the relevant parts:
-> 1. jsp engine converts <%@ include file="foo.jsp" %> to:


2. jsp engine converts the <jsp:include page="foo.jsp" flush="true"/> to:

The pageContext.include(String relativeUrlPath); is a method of the javax.servlet.jsp.PageContext class
It must work at request time. You cant pass parameters to the included page (my deduction), but you may set the included page dynamically (as the URL is a parameter).
Puh. Lots of before-breakfast-work . Correct me if I am wrong.
Axel
[ January 22, 2002: Message edited by: Axel Janssen ]
[ January 22, 2002: Message edited by: Axel Janssen ]
[ January 22, 2002: Message edited by: Axel Janssen ]
 
Reda Mokrane
Ranch Hand
Posts: 237
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Axel, thanks for a quick reply, that was an excellent explanation.
Thanks again
 
ersin eser
Ranch Hand
Posts: 1072
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

The pageContext.include(String relativeUrlPath); is a method of the javax.servlet.jsp.PageContext class
It must work at request time. You cant pass parameters to the included page

Can't you encodeURL and pass? Ie: when jsessionid is encoded in url ?
 
Axel Janssen
Ranch Hand
Posts: 2166
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by ersin eser:

Can't you encodeURL and pass? Ie: when jsessionid is encoded in url ?

Sorry. Forgot that. You should allways be able to pass variables with the url. Haven't tested it.
Axel
[ January 24, 2002: Message edited by: Axel Janssen ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic