• 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:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

include page directives

 
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Dave Bosky
Ranch Hand
Posts: 72
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Bear Bibeault
Sheriff
Posts: 67645
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic