Prentice Hall and Sun Microsystems. Personal use only; do not redistribute.
268
Chapter 12 Including Files and Applets in JSP Documents
12.1 Including Files at Page 
Translation Time
You use the 
include
 directive to include a file in the main JSP document at
the time the document is translated into a servlet (which is typically the first
time it is accessed). The syntax is as follows:
<%@ include file="Relative URL" %>
There are two ramifications of the fact that the included file is inserted at
page translation time, not at request time as with 
jsp:include
  (Section
12.2).
First, you include the actual file itself, unlike with 
jsp:include
 , where
the server runs the page and inserts its output. This approach means that the
included file can contain JSP constructs (such as field or method declara 
tions) that affect the main page as a whole.
Second, if the included file changes, all the JSP files that use it need to be
updated. Unfortunately, although servers are allowed to support a mecha 
nism for detecting when an included file has changed (and then recompiling
the servlet), they are not required to do so. In practice, few servers support
this capability. Furthermore, there is not a simple and portable  retranslate
this JSP page now  command. Instead, you have to update the modification
date of the JSP page. Some operating systems have commands that update
the modification date without your actually editing the file (e.g., the Unix
touch
 command), but a simple portable alternative is to include a JSP com 
ment in the top level page. Update the comment whenever the included file
changes. For example, you might put the modification date of the included
file in the comment, as below.
<%   Navbar.jsp modified 3/1/00   %>
<%@ include file="Navbar.jsp" %>
Core Warning
If you change an included JSP file, you must update the modification dates 
of all JSP files that use it.
For example, Listing 12.1 shows a page fragment that gives corporate con 
tact information and some per page access statistics appropriate to be
included at the bottom of multiple pages within a site. Listing 12.2 shows a
page that makes use of it, and Figure 12 1 shows the result.
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




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

jsp web hosting

 

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