• 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 v/s jsp:include

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

I'm wondering what is the difference between following 2 lines. I really appreciate any help.

<%@include file="Help.html"%>
<jsp:include page="Help.html" flush="false"></jsp:include>

Thanks
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Viji,
I think the scriptlet one includes the file at compile time while the tag includes the file at rumtime.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne is correct.
The advantage to using the page directive is that the import only get's done at compile time (think of it as pasting the two source files together before compiling). Since it's only done once, it's more efficient for lightweight imports.

One of the down sides is that everything always gets imported, even it it's not used.
Example:


In this case, both file_A and file_B will be included even though only one of them will ever be used.

The jsp:include will check the condition at run time and then import the correct file when needed.

Another thing to watch for with the page directive is that some containers (older versions of Tomcat for instance) will only check the parent for updates. This means that if you update the code in your include file, the change will not show until you force a recompile of the page it's included in. Tomcat now checks both.

Also, one drawback to the jsp:include action is that the output from the included page can't be JSP that defines variables or behaviour used in the calling page because the calling page will have already been run before the include is.
[ January 01, 2005: Message edited by: Ben Souther ]
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. <%@include file="Help.html"%>

This is static include where in the "Help.html" file contents will be included in the current jsp only once when this JSP compiles. So any changes that might occur in "Help.html" are not reflected at run time. To include such latest changes, one has recompile the JSP.

Thus it makes a copy of the included page and copies it into a JSP page (the "including page") during translation and known as a static include (or translate-time include)


2. <jsp:include page="Help.html" flush="false"></jsp:include>

This is dynamic include as here the "Help.html" page is dynamically included at runtime and thus any time a change in "Help.html" would be included at runtime without a need if recompiling the current JSP....

So dynamically includes output from the included page within the output of the including page, during runtime and known as a dynamic include (or runtime include)


Thus dynamic include has an advantage in situations where your included page changes frequently and it is required to reflect the latest changes....
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic