Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

include directive VS Include Tag

 
Sanjay Deshpande
Ranch Hand
Posts: 111
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the difference between the include directive and the include action tag in JSP? When would you prefer one over the other
 
Chris Baron
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
if you determin your include-page dynamically
xml-syntax is better:
<jsp:include page="<%=includePage%>" />
cb
 
Peter den Haan
author
Ranch Hand
Posts: 3252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <%@include%> directive is evaluated compile-time, when the JSP is converted into Java. It must include an actual file on the filesystem. The file may contain anything, and certainly doesn't need to contain a complete JSP; it will be included verbatim in the page source before the page gets compiled (as in the #include directive of the C preprocessor, if you're familiar with that).
The <jsp:include/> action is evaluated request-time. That's why, as mentioned above, you have to use the include action if you dynamically want to change the stuff you include. The included resource doesn't have to be a file: you can include any web-app resource, for instance a servlet. If you include a JSP file, it must be a complete JSP. The HTML generated by the included JSP gets inserted into the HTML generated by the including JSP.
There is no performance penalty to using the include directive, but include actions are slower because they are evaluated as part of a request. Actions are often cleaner and much more versatile though, especially if you need any dynamic behaviour.
- Peter
[ April 03, 2003: Message edited by: Peter den Haan ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic