[Top] [Prev] [Next] [Bottom]

Include Directive

Includes a static file in a JSP file, parsing the file's JSP elements.

JSP Syntax

<%@ include file="relativeURL" %>

Examples

include.jsp:
<html>
<head><title>An Include Test</title></head>
<body bgcolor="white">
<font color="blue">
The current date and time are
<%@ include file="date.jsp" %>
</font>
</body>
</html>

date.jsp:
<%@ page import="java.util.*" %>
<%= (new java.util.Date() ).toLocaleString() %>
Displays in the page:
The current date and time are
Aug 30, 1999 2:38:40

Description

The <%@ include %> directive inserts a file of text or code in a JSP file at translation time, when the JSP file is compiled. When you use the <%@ include %> directive, the include process is static. A static include means that the text of the included file is added to the JSP file. The included file can be a JSP file, HTML file, or text file. If the included file is a JSP file, its JSP elements are parsed and their results included (along with any other text) in the JSP file.

You can only use include to include static files. This means that the parsed result of the included file is added to the JSP file where the <%@ include %> directive is placed. Once the included file is parsed and included, processing resumes with the next line of the calling JSP file.

The included file can be an HTML file, a JSP file, a text file, or a code file written in the Java programming language. Be careful, though, that the included file does not contain <html>, </html>, <body>, or </body> tags. Because the entire content of the included file is added at that location in the JSP file, these tags would conflict with the same tags in the calling JSP file, causing an error.

Some of the behaviors of the <%@ include %> directive depend on the particular JSP container you are using, for example:

Attributes

Tip

See Also



[Top] [Prev] [Next] [Bottom]

Copyright © 1999, Sun Microsystems, Inc. All rights reserved.