*
The moose likes JSP and the fly likes include directive VS Include Tag Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "include directive VS Include Tag" Watch "include directive VS Include Tag" New topic
Author

include directive VS Include Tag

Sanjay Deshpande
Ranch Hand

Joined: May 22, 2001
Posts: 111
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

Joined: Mar 21, 2003
Posts: 1049
Hi,
if you determin your include-page dynamically
xml-syntax is better:
<jsp:include page="<%=includePage%>" />
cb
Peter den Haan
author
Ranch Hand

Joined: Apr 20, 2000
Posts: 3252
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 ]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: include directive VS Include Tag