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
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.
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
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.