The jsp:include tag is handled at request time. For every request that
comes in for the index.jsp URL, the content.jsp servlet will be run when the
jsp:include tag is encountered. In principle, this could have been done
at translation time; the chunk of HTML from the content.jsp file could have been
dropped right into the index.jsp servlet. This would be much less powerful,
however. By processing includes at request time, the contents of the included
file can change independently of the main file.
<%@include file="contents.jsp" %>
This tag is called a directive because it directs the page
compiler to take some action. In this case, when it sees the directive, the page
compiler will embed the contents of the contents.jsp file directly into the
servlet that it is building for index.jsp. Subsequently, if the contents.jsp
file is edited, index.jsp will not change. Browsers will continue to get the old
message until the page compiler is forced to rebuild the index.jsp servlet.
Note- that the include directive specifies what is to be
included with file=, whereas the jsp:include tag specifies
page=. This nicely encapsulates the differences between the two: The
directive includes a file as it is building the servlet at request time, and the
tag includes another page at request time.
No comments:
Post a Comment