• 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 directive VS Include Tag

 
Ranch Hand
Posts: 111
  • 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 the include directive and the include action tag in JSP? When would you prefer one over the other
 
Ranch Hand
Posts: 1061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
if you determin your include-page dynamically
xml-syntax is better:
<jsp:include page="<%=includePage%>" />
cb
 
author
Posts: 3252
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
reply
    Bookmark Topic Watch Topic
  • New Topic