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~