Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

@include v/s jsp:include  RSS feed

 
Viji Laxmi
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • 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
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36406
454
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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 ]
 
Neeraj Gupta
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • 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....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!