Forums Register Login

include page directives

+Pie Number of slices to send: Send
If I wanted to include a header file on all my pages which type of include statement would I use? What is the difference between the two and when should you use one over the other?
<%@ include file="/includes/header.jsp" %>
<% jsp:include page="/includes/header.jsp" /%>
Thanks,
Dave
+Pie Number of slices to send: Send
The include directive reads the included fragment at page translation time. The fragment is treated as if it were part of the page when it is translated.
The jsp:include action is executed at request time, and causes the resource to be evaluated and its result to be included in the response output stream.
If the "header" you want to include is for declaration (such as imports and taglibs), you'll want to use the directive.
If it's a display header (common nav elements, for example), you could go either way, but I ternd to prefer the jsp:include action for such purposes.
+Pie Number of slices to send: Send
That clears it up!
So if the file I'm including contains an image/menu it doesn't really matter if I use action or directive.
Is there a preferred method or common best practices to follow?
Thanks Again!
Dave
+Pie Number of slices to send: Send
While there is a marginal request-time performance benefit to the directive, I'd say that you should use whichever makes the most sense in the context of your app.
If your fragment requires parameterization, that's best accomplished with the action.
Thanks tiny ad, for helping me escape the terrible comfort of this chair.
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 1107 times.
Similar Threads
JSP Components
style sheet and image paths
HELP! Weird Include problem!
include a file between webapps
A jsp deployment problem
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 21:59:34.