Java Server Pages standard tag Libray (JSTL): JSP standards Tag Library, which encapsulates the common Core functionality of JSP applications. JSTL supports common, structured tasks such as iterations, conditional judgments, XML document manipulation, internationalization tags, and SQL tags. In addition to these, it also provides a framework for using custom labels with integrated Jstl.
Jstl refers to the standard tag library, according to its function can be summed up into five categories:
- Core Tag Library
- XML Tag Library
- Formatting tag Libraries
- Database Tag Library
- JSTL function Tag Library
- Jstl Tag Library Installation
Apache Tomcat installs the JSTL library steps as follows:
Download the binary package (Jakarta-taglibs-standard-current.zip) from the standard tag Library of Apache.
- Official:http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/
Download the Jakarta-taglibs-standard-1.1.2.zip package and unzip it to jakarta-taglibs-standard-1.1.2/lib/ Two jar files under: Standard.jar and Jstl.jar files are copied to/web-inf/lib/.
Jstl can only be run on containers that support JSP1.2 and Servlet2.3 specifications.
- Reasons to use the tag library
- Keep the program good readability. Page Write Java code is not easy to maintain and modify, the readability is very poor.
- Strong reusability. Jstl tags can be reused indefinitely.
- The idea of layering can be realized. Separates the business from the display.
- Scalability is good. Jstl tags can only be imported into the JSTL package when used.
- More standardized, follow the XML standard.
- Simplified page, beautiful page.
Core Tag Library
The core tag is the most commonly used jstl tag. In order to use the Jstl class library on a JSP page, the TAGLIB directive must be used in the following format : <% @taglib uri= "" prefix= "%>
Example: <% @taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>
The prefix can be anything, and following the specification can make the code in the team more similar to those written by different people, so it is recommended to use a pre-designed prefix.
So let's take a look at the common General action commands (out tags, set tags,remove tags):
An out tag evaluates an expression and outputs the result to the current jspwriter. There are two forms of out syntax, subject content and no principal content:
For example:
Before JSP2.0, out tags are the easiest way to output domain-limited object values. After JSP2.0, you can safely use the EL expression unless you need to convert a value to character: ${x}
The following work can be done with the set tag:
① creates a string and a domain-limited variable that references the string
② create a restricted domain variable and reference one of the restricted domain variables that already exist
③ setting properties for domain-limited objects
If you create a domain variable with set, then the entire JSP page after that tag will be able to use that variable.
<c:set> Common Properties of the tag (store values in scope or assign values to variable properties in JavaBean)
This form allows JSP code to be included in the main content
Use the Remove tag to remove the restricted domain variable with the following syntax:
If no range is specified, then all four ranges can be found to be deleted.
Note: The object referenced by the domain-limited variable is not deleted. Therefore, if another domain object is referencing the object, the object can still be accessed through another domain-limited object.
Write here, everyone to JSTL Core Tag Library General action command also know about, then next to explain the core Tag Library conditions Action command follow-up will for everyone, please pay attention to Shanghai still school java.
The core tag Library of the basic tutorial of Jstl tag Library (i)