Jsp Directives
# JSP Directives
JSP directives are used to set attributes related to the entire JSP page, such as the page's encoding and scripting language.
The syntax format is as follows:
A directive can have many attributes, which exist in the form of key-value pairs and are separated by commas.
The three directive tags in JSP:
| **Directive** | **Description** |
| --- | --- |
| | Defines page-dependent attributes, such as scripting language, error page, caching requirements, etc. |
| | Includes other files |
| | Introduces the definition of a tag library |
* * *
## Page Directive
The Page directive provides instructions for the container on how to use the current page. A JSP page can contain multiple page directives.
The syntax format for the Page directive:
Equivalent XML format:
* * *
## Attributes
The following table lists the attributes associated with the Page directive:
| **Attribute** | **Description** |
| --- | --- |
| buffer | Specifies the size of the buffer used by the out object |
| autoFlush | Controls the buffer of the out object |
| contentType | Specifies the MIME type and character encoding for the current JSP page |
| errorPage | Specifies the error handling page to redirect to when an exception occurs in the JSP page |
| isErrorPage | Specifies whether the current page can serve as the error handling page for another JSP page |
| extends | Specifies the class from which the servlet inherits |
| import | Imports Java classes to be used |
| info | Defines descriptive information for the JSP page |
| isThreadSafe | Specifies whether access to the JSP page is thread-safe |
| language | Defines the scripting language used in the JSP page, default is Java |
| session | Specifies whether the JSP page uses sessions |
| isELIgnored | Specifies whether to evaluate EL expressions |
| isScriptingEnabled | Determines whether scripting elements can be used |
* * *
## Include Directive
JSP can include other files using the include directive. The included file can be a JSP file, an HTML file, or a text file. The included file is treated as part of the JSP file and is compiled and executed together.
The syntax format for the include directive is as follows:
The filename in the **include** directive is actually a relative URL address.
If you do not associate a path with the file, the JSP compiler will look for it in the current path by default.
Equivalent XML syntax:
* * *
## Taglib Directive
The JSP API allows users to define custom tags. A custom tag library is a collection of custom tags.
The Taglib directive introduces the definition of a collection of custom tags, including the library path and custom tags.
The syntax for the Taglib directive:
The uri attribute determines the location of the tag library, and the prefix attribute specifies the prefix for the tag library.
Equivalent XML syntax:
YouTip