• Post Reply Bookmark Topic Watch Topic
  • New Topic

The diff btw the two include method

 
Feybian Yip
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to ask the main difference btw the method
1. <%@ include file="page1.jsp" %>
2. <jsp:include page="page1.jsp" flush="true" />
?
thx~
 
Jason Kilgrow
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Great question!
This little difference escaped me for quite a while.
Here's the scoop (you can also look it up on sun's web site).
<%@ include file="page1.jsp" %>
means "this file is static put a copy of it right here". The file could be anything. Text, html, jsp, you name it. It'll stick a copy of that file right where that tag is.
<jsp:include page="page1.jsp" flush="true" />
means "run this jsp page and put the output here" (loose translation). Basically, this is a dynamic page. The 2 places I've seen this most useful is when somone has an html page but wants just a small area of dynamic content. So, you write a little jsp that dynamically builds the content. It's a free-standing, fully functional jsp. Of course, their page must become a jsp by naming it from "our.html" to "our.jsp". The other area where I've seen this used is if your servlet container does not support dynamic compilation/binding. If this is the case, then you'll want to run the included jsp each time just in case it has changed because your servlet container won't know to recompile the included file into the main file when the included one has changed. This is sort of a kludge and it'll probably go away in time leaving the true nature of the <jsp:include.../> tag for what it's meant for.
Originally posted by Feybian Yip:
Hi,
I want to ask the main difference btw the method
1. <%@ include file="page1.jsp" %>
2. <jsp:include page="page1.jsp" flush="true" />
?
thx~

 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'll just add a couple of points:
Firstly the implementation is vendor specific so test the behaviour before taking them for granted. I'm not sure how every server behaves but (for example) they changed between Weblogic versions 4.5 and 5 (from memory).
Secondly, the static inclusion method is a little more efficient since it involves executing a single class, whereas the dynamic version requires a call to a separate class so there'll be an overhead.
OK, I've finished now
Dave.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!