How to Add Text File or Code in a JSP File at Translation Time

JSP Include Directive Tag

The include directive inserts a file of text or code in a JSP file at translation time, when the JSP file is compiled. 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 tags 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 similar tags in the JSP file. Some of the behaviours of the include directive depend on the JSP engine, for

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

Attributes
file="relativeURL"
The pathname to the included file, which can contain any text or code that is valid in a JSP file. The value of file is always a relative URL. Simply put, a relative URL is just the path segment of an URL, without the protocol, port, or domain:
"error.jsp"
"/Android/88-
application
s-types.htm"
"/Android/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.

JSP Include Directive Tag 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
Jan 30, 2011 2:38:40

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


Related Topic JSP Page Directive for Translation Unit
Javascript Spell Checker Embedded Code, Text Area Object
JSP Scriptlets Tag for Variable Expressions and Statements Declaration
List of Mysql Error Code and Description
How to Create tar.gz and tar.bz2

nScraps.com © 2011   Privacy Policy  Terms of Service  Feedback