• Post Reply Bookmark Topic Watch Topic
  • New Topic

on jsps  RSS feed

 
vara prasad
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what is the difference between <%@ page include="xxx"%>
<jsp:include page="xxx" />

i know that above page tag will generate a single servlet.
where as <jsp:include > generate two servlet corresponding to jsps. Apart from this is there any difference?
 
Jeroen Wenting
Ranch Hand
Posts: 5093
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The first does a static include, pretty much a direct equivalent of a C #include statement.
It copies the source from the other file at compile time into your own source and compiles the result.

The second is a dynamic include. It includes into the outputstream from the JSP the result of executing the other compilation unit at runtime.
It's similar to calling a function on a class and printing the result of that function to the output.

Which you choose depends on what you want to achieve though sometimes you will be forced into one or the other.
For example we've been forced to split up some very large JSPs (thousands of lines of code including tabbed dialogs, large conditional display units, etc. etc.) into several dynamically included units because the single compilation unit became too large for the JVM to handle.
As you may know a single method in Java may not exceed 64KB of compiled code. As the entire content of a JSP will make up the service method of your generated servlet it is entirely possible that a highly complex JSP will exceed that limit unless using dynamic includes.

Another advantage of dynamic includes is that changes in the included part do not require recompilation of the containing JSP (which sometimes the JSP engine fails to see the need of when using static includes, forcing you to clear your cache and/or restart the web application).
As a price you may get some more complexity and potentially a small loss of performance.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!