|
Home
TOC Index |
|
Including Content in a JSP Page
There are two mechanisms for including another Web resource in a JSP page: the
includedirective and thejsp:includeelement.The
includedirective is processed when the JSP page is translated into a servlet class. The effect of the directive is to insert the text contained in another file-- either static content or another JSP page--in the including JSP page. You would probably use theincludedirective to include banner content, copyright information, or any chunk of content that you might want to reuse in another page. The syntax for theincludedirective is as follows:<%@ include file="filename" %>For example, all the bookstore application pages include the file
banner.jspwhich contains the banner content, with the following directive:<%@ include file="banner.jsp" %>In addition, the pages
bookstore.jsp,bookdetails.jsp,catalog.jsp, andshowcart.jspinclude JSP elements that create and destroy a database bean with the following directive:<%@ include file="initdestroy.jsp" %>Because you must statically put an
includedirective in each file that reuses the resource referenced by the directive, this approach has its limitations. For a more flexible approach to building pages out of content chunks, see A Template Tag Library.The
jsp:includeelement is processed when a JSP page is executed. Theincludeaction allows you to include either a static or dynamic resource in a JSP file. The results of including static and dynamic resources are quite different. If the resource is static, its content is inserted into the calling JSP file. If the resource is dynamic, the request is sent to the included resource, the included page is executed, and then the result is included in the response from the calling JSP page. The syntax for thejsp:includeelement is:<jsp:include page="includedPage" />
Note: Tomcat will not reload a statically included page that has been modified unless the including page is also modified.
The
dateapplication introduced at the beginning of this chapter includes the page that generates the display of the localized date with the following statement:<jsp:include page="date.jsp"/>
|
Home
TOC Index |
|
This tutorial contains information on the 1.0 version of the Java Web Services Developer Pack.
All of the material in The Java Web Services Tutorial is copyright-protected and may not be published in other works without express written permission from Sun Microsystems.