![]() |
The Java Developers Almanac 1.4Order this book from Amazon. |
e1054. Including a File in a JSP PageTo include an HTML or JSP fragment in a JSP file, theinclude
directive is used. The effect is essentially equivalent to replacing
the directive with the contents of the included file. This means that
an included fragment can access any objects defined in the main JSP
page.
The include file specified by
This example includes a file called <%@ include file="relativeFragment.jsp" %>This example includes a file called / absoluteFragment.jsp
which is located relative to the web application's root:
<%@ include file="/absoluteFragment.jsp" %>At the time the main JSP page is accessed, the include directive
permanently captures the current contents of an included
file. Changes to the included file will not affect the results of the
main JSP page. If the application depends on capturing the contents
of the included file at the time of each request, then an include
action should be used.
These examples demonstrate how to use an <jsp:include page="relativeDynFragment.jsp" /> <jsp:include page="relativeDynFragment.html" /> <jsp:include page="/absoluteDynFragment.jsp" /> <jsp:include page="/absoluteDynFragment.html" />It is also possible to dynamically choose the file to include. This example determines the file to include from a request parameter: <jsp:include page='<%= request.getParameter("incFile") %>' />See also e1055 Passing Parameters to Another JSP Page.
e1055. Passing Parameters to Another JSP Page e1056. Using a Bean in a JSP Page
© 2002 Addison-Wesley. |