http://www-it.fmi.uni-sofia.bg/courses/WDB/references/JSP%20syntax/syntaxref07.html

Include Directive

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

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 translated and included (along with any other text) in the JSP file. Once the included file is translated and included, the translation process resumes with the next line of the including 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 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 file, these tags would conflict with the same tags in the including JSP file, causing an error.

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

  • The included file might be open and available to all requests, or it might have security restrictions.
  • The JSP page might be recompiled if the included file changes.

Attributes

  • file="relativeURL"

    The pathname to the included file, which is always a relative URL. Simply put, a relative URL is just the path segment of an URL, without a protocol, port, or domain name, like this:

    "error.jsp"
    "/templates/onlinestore.html"
    "/beans/calendar.jsp"

    If the relative URL starts with /, the path is relative to the JSP application's context, which is a javax.servlet.ServletContext object that is in turn stored in the application object. If the relative URL starts with a directory or file name, the path is relative to the JSP file.

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.


'Web Develop. > JSP' 카테고리의 다른 글

JSP 페이지 구성요소  (0) 2014.10.12
Include Directive  (0) 2014.09.30
<jsp:include>  (0) 2014.09.30
EL(Expression Language)  (0) 2014.09.23

+ Recent posts