May 12, 2021 JSP
JSP instructions are used to set properties related to the entire JSP page, such as how the page is encoded and the scripting language.
The syntax format is as follows:
<%@ directive attribute="value" %>
Instructions can have many properties that exist as key-value pairs and are separated by commas.
Three instruction labels in JSP:
Instructions | Describe |
---|---|
<%@ page ... %> | Define page dependency properties, such as scripting language, error pages, cache requirements, and so on |
<%@ include ... %> | Contains other files |
<%@ taglib ... %> | Introduce the definition of a label library |
The Page directive provides the container with instructions for using the current page. A JSP page can contain multiple page instructions.
The syntax format of the Page instruction:
<%@ page attribute="value" %>
Equivalent XML format:
<jsp:directive.page attribute="value" />
The following table lists the properties associated with the Page directive:
Property | Describe |
---|---|
buffer | Specifies the size of the out object that uses the buffer |
autoFlush | Controls the cache area of the out object |
contentType | Specifies the MIME type and character encoding of the current JSP page |
errorPage | Specifies the error-handling page that needs to be turned over when an exception occurs on the JSP page |
isErrorPage | Specify whether the current page can be treated as another JSP page for error handling |
extends | Specify which class the servlet inherits from |
import | Import the Java class you want to use |
info | Define the description information for the JSP page |
isThreadSafe | Specify whether access to the JSP page is thread-safe |
language | The scripting language used to define the JSP page is Java by default |
session | Specify whether the JSP page uses session |
isELIgnored | Specify whether to execute the EL expression |
isScriptingEnabled | Determines whether the script element can be used |
JSPs can include additional files through the include directive. T he included file can be a JSP file, an HTML file, or a text file. The file is contained as if it were part of the JSP file and will be compiled and executed at the same time.
The syntax format of the Include instruction is as follows:
<%@ include file="relative url" %>
The file name in the Include instruction is actually a relative URL. If you do not associate a path with a file, the JSP compiler looks under the current path by default.
Equivalent XML syntax:
<jsp:directive.include file="relative url" />
The JSP API allows users to customize labels, and a custom label library is a collection of custom labels.
The Taglib directive introduces a definition of a custom label collection, including library paths, and custom labels.
The syntax of the Taglib instruction:
<%@ taglib uri="uri" prefix="prefixOfTag" %>
The uri property determines the location of the label library, and the prefix property specifies the prefix of the label library.
Equivalent XML syntax:
<jsp:directive.taglib uri="uri" prefix="prefixOfTag" />