Preface

Comment

Declaration

Expression

Scriptlet

EL Expression

Directives

Attribute Directive

Include Directive

Page Directive

Tag Directive

Taglib Directive

Variable Directive

Standard Actions

<jsp:attribute>

<jsp:body>

<jsp:element>

<jsp:doBody>

<jsp:forward>

<jsp:getProperty>

<jsp:include>

<jsp:invoke>

<jsp:output>

<jsp:plugin>

<jsp:root>

<jsp:setProperty>

<jsp:text>

<jsp:useBean>

Include Directive

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

JSP Syntax

<%@ include file="relativeURL" %>

OR

<jsp:directive.include file="relativeURL" />

XML Syntax

<jsp:directive.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

An include directive inserts a file of text or code in a JSP page at translation time, when the JSP page 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 page. The included file can be a JSP page, HTML file, XML document, or text file. If the included file is a JSP page, its JSP elements are translated and included (along with any other text) in the JSP page. Once the included file is translated and included, the translation process resumes with the next line of the including JSP page.

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

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

Attributes

Tip

If you are including a text file and do not want the text to be displayed in the JSP page, place the text in a comment element.

See Also



宏飞网络是你学习web开发、测试web程序实例、和培养职业技能的首选网站。我们提供例子也许有些简单,但对理解基本概念有帮助。

我们尽量避免在教程、参考及例子中出现错误,但不能保证所有的内容都是正确的。

你使用本网站时,我们默认你已经阅读并接受了我们的隐私政策。

Copyright 2003-2011宏飞网络 版权所有