Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
12.2 Including Files at Request Time
271
Although the included files cannot contain JSP, they can be the result of
resources that use JSP to create the output. That is, the URL that refers to
the included resource is interpreted in the normal manner by the server and
thus can be a servlet or JSP page. This is precisely the behavior of the
include
method of the
RequestDispatcher
class, which is what servlets
use if they want to do this type of file inclusion. See Section 15.3 (Including
Static or Dynamic Content) for details.
The
jsp:include
element has two required attributes, as shown in the
sample below:
page
(a relative URL referencing the file to be included) and
flush
(which must have the value
true
).
Although you typically include HTML or plain text documents, there is no
requirement that the included files have any particular file extension. How
ever, the Java Web Server 2.0 has a bug that causes it to terminate page pro
cessing when it tries to include a file that does not have a
.html
or
.htm
extension (e.g.,
somefile.txt
). Tomcat, the JSWDK, and most commercial
servers have no such restrictions.
Core Warning
Due to a bug, you must use
.html
or
.htm
extensions for included files
used with the Java Web Server.
As an example, consider the simple news summary page shown in Listing
12.3. Page developers can change the news items in the files
Item1.html
through
Item4.html
(Listings 12.4 through 12.7) without having to update
the main news page. Figure 12 2 shows the result.
Listing 12.3 WhatsNew.jsp
What s New
HREF="JSP Styles.css"
TYPE="text/css">
Second edition of this book: www.coreservlets.com; Sequel: www.moreservlets.com.
Servlet and JSP training courses by book's author: courses.coreservlets.com.
footer
Our partners:
PHP: Hypertext Preprocessor Best Web Hosting
Java Web Hosting
Jsp Web Hosting
Cheapest Web Hosting
Visionwebhosting.net Business web hosting division of Web
Design Plus. All rights reserved