There are three types of directive tags in the JSP-
Serial Number |
instruction |
Description |
1 |
<%@ page ... %> |
Defines page-related properties, such as scripting language, error pages, and buffering requirements. |
2 |
<%@ include ... %> |
Include files in the compile phase. |
3 |
<%@ taglib ... %> |
A tag library that contains custom actions used in the claims page |
The directives in the JSP are page
used to provide the container with instructions related to the current JSP page. You can use directives to encode anywhere in a JSP page page
. By convention, page
directives are encoded at the top of the JSP page.
The following is page
the basic syntax of the instruction-
<%@ page attribute = "value" %>
Html
You can write the above syntax using XML, as follows:
<jsp:directive.page attribute = "value" />
Xml
Property
The following table lists the page
properties associated with the directive-
Serial Number |
Properties |
Description |
1 |
buffer |
Specifies the buffer model for the output stream. |
2 |
autoFlush |
Controls the behavior of the servlet output buffers. |
3 |
contentType |
Defines the character encoding scheme. |
4 |
errorPage |
Defines another URL that reports the JSP that Java does not check for runtime exceptions. |
5 |
isErrorPage |
Indicates whether this JSP page is a URL specified by the properties of another JSP page errorPage . |
6 |
extends |
Specifies the superclass that the generated servlet must extend. |
7 |
import |
Specifies a list of packages or classes used in the JSP, just like a Java import statement. |
8 |
info |
Defines a string that can be accessed using the method of the servlet getServletInfo() . |
9 |
isThreadSafe |
Defines the threading model of the generated servlet. |
10 |
language |
Defines the programming language used in JSP pages. |
11 |
session |
Specifies whether the JSP page participates in an HTTP session |
12 |
isELIgnored |
Specifies whether an El expression in a JSP page is ignored. |
13 |
isScriptingEnabled |
Determines whether the script element is allowed to be used. |
1. Buffer Property
buffer
property specifies the buffering characteristics of the server output response object.
You can write a none
value that specifies not to use buffering so that the servlet output is immediately directed to the response object, or you can write a KB
maximum buffer size in units, which instructs the servlet to write to the buffer before writing the response.
To instruct the servlet to write output directly to the response output object, use the following command-
<%@ page buffer = "none" %>
Html
Use the following command to instruct the servlet to write output to buffers that are not less than 64KB
bytes in size-
<%@ page buffer = "64kb" %>
Html2. AutoFlush Properties
autoFlush
property specifies whether the buffer output is automatically refreshed when the buffer is populated, or whether an exception is thrown to indicate a buffer overflow.
true
The (default) value indicates an automatic buffer flush, and the false
value indicates an exception was thrown.
When the output buffer of the servlet is full, the following instruction causes the servlet to throw an exception, using the following statement-
<%@ page autoFlush = "false" %>
Html
This directive causes the servlet to flush the output buffer when full output is
<%@ page autoFlush = "true" %>
Html
Typically, buffer
and autoFlush
attributes are page
encoded in directives, as follows:
<%@ page buffer = "16kb" autoflush = "true" %>
Html3. ContentType Properties
contentType
property to set the character encoding of the JSP page and the generated response page. The default content type text/html
is:, which is the standard content type for an HTML page.
If you want to output from a JSP as XML, use the following page
directives-
<%@ page contentType = "text/xml" %>
Html
The following statement indicates that the page generated by the browser is rendered as HTML-
<%@ page contentType = "text/html" %>
Html
The following instruction sets the content type to: Microsoft Word document-
<%@ page contentType = "application/msword" %>
Html
You can also specify the character encoding of the response. For example, if you want to specify a result page that returns a browser using:UTF-8, you can use the following page
Directive-
<%@ page contentType = "text/html:charset=UTF-8" %>
Html4. ErrorPage Properties
If you want to specify an error page when an error occurs while the current page is running, the errorPage
property tells the JSP engine which page to display. errorPage
the value of the property is a relative URL.
When all uncaught exceptions are thrown, the following instruction is used to specify what is displayed when the page is faulted MyErrorPage.jsp
-
<%@ page errorPage = "MyErrorPage.jsp" %>
Html5. Iserrorpage Properties
isErrorPage
property indicates that the current JSP page can be used as an error page for another JSP.
isErrorPage
The value can be true
either or false
. isErrorPage
the default value for the property is false
.
For example handleError.jsp
, isErrorPage
set the option to true
, because it should handle the error-
<%@ page isErrorPage = "true" %>
Html6. Extends Properties
extends
property specifies the superclass that the generated servlet must extend.
For example, the following directive instructs the JSP converter to generate a servlet so that the servlet extends somePackage.SomeClass
-
<%@ page extends = "somePackage.SomeClass" %>
Html7. Import Properties
import
The property is functionally identical to the Java import statement and is similar to the Java import statement. The import
value of the option is the name of the package to be imported.
For example, to import java.sql.*
, use the following page
directives-
<%@ page import = "java.sql.*" %>
Html
To import multiple packages, you can use commas to separate them, as follows:
<%@ page import = "java.sql.*,java.util.*" %>
Html
By default, containers are automatically imported java.lang.*
, javax.servlet.*
javax.servlet.jsp.*
and javax.servlet.http.*
.
8. Info Property
info
property allows you to provide a description of the JSP. The following is a code example-
<%@ page info = "This JSP Page Written By Maxsu" %>
Html9. IsThreadSafe Properties
isThreadSafe
Option to mark the page as thread safe. By default, all JSPs are considered thread-safe. If you isThreadSafe
set the option to false
, the JSP engine ensures that only one thread is executing the JSP at a time.
The following page
instruction isThreadSafe
sets the value of the option to false
-
<%@ page isThreadSafe = "false" %>
HtmlLanguage Properties
language
property indicates the programming language used in JSP page scripting.
For example, since we usually use Java as the scripting language, the language
options can be set as follows:
<%@ page language = "java" %>
HtmlOne . Session Properties
session
property indicates whether the JSP page uses an HTTP session. If the setting value is true
, the JSP page can access the built-in session
object, setting the value to false
indicate that the JSP page cannot access the built-in session
object.
The following directives allow JSP pages to use any built-in session
object methods, such as: session.getCreationTime()
or session.getLastAccessTime()
-
<%@ page session = "true" %>
Htmliselignored Properties
isELIgnored
property to disable evaluation of expression language (EL) expressions introduced in JSP 2.0.
isELIgnored
The default value of the property is true, which means that the expression ${...}
is evaluated by the JSP specification. If the property is set to, the expression is evaluated for evaluation and is false
treated as static text content.
The following instruction set expression is not evaluated-
<%@ page isELIgnored = "false" %>
Htmlisscriptingenabled Properties
isScriptingEnabled
property determines whether the script element is allowed to be used.
isScriptingEnabled
The default value for true
the property is, which represents the enable script, expression, and declaration. If the value of the property is set to false
, then a conversion error is thrown if the JSP uses any script, either an expression (non-EL) or a declaration.
If you want to restrict the use of scripts, expressions (not el) or declarations, you isScriptingEnabled
can set the value of the property to false
-
<%@ page isScriptingEnabled = "false" %>
include
directive is used to include a file during the compilation phase. This instruction tells the container to merge the contents of other external files into the current JSP file during the compilation phase. You can use directives to encode anywhere in the JSP page include
.
The general form of use of this directive is as follows:
<%@ include file = "relative url" >
include
The file name in the directive is actually a relative URL. If you specify only a file name that does not have an associated path, the JSP compiler assumes that the file is in the same directory as the JSP.
You can write the preceding code in XML with the same effect as follows:
<jsp:directive.include file = "relative url" />
The JSP API allows you to customize JSP tags, such as HTML or XML tags, which are a set of user-defined tags that implement custom behavior.
taglib
The directive declaration JSP page uses a set of custom labels, identifies the location of the library, and provides a way to identify the custom label in the JSP page.
taglib
The instruction follows the syntax given below-
<%@ taglib uri="uri" prefix = "prefixOfTag" >
Html
Here, the uri
property value resolves to the location that the container understands, and the prefix
attribute notifies the container where the tag is a custom action.
You can write the above syntax using XML, as follows:
<jsp:directive.taglib uri = "uri" prefix = "prefixOfTag" />
Xml
When you use a custom label, it is usually <prefix:tagname>
the form. The prefix is the same as the taglib
prefix specified in the directive, and the tag name is the name of the tag implemented in the tag library.
Java Record-jsp Instructions