The full name of jstl is assumerverpages standard tag library, that is, the jspstandard tag Library (the package behind the download is jakarta-taglibs-standard-current.zip). Its main function is to provide a standard and common tag library for JSP web developers. Developers can use these labels to replace Java code on JSP pages, so as to improve program readability and reduce program maintenance difficulty.
Jstl Introduction
Jstl labels are Based on JSP pages. These labels can be inserted into JSP code. In essence, jstl is a set of labels defined in advance. These labels encapsulate different functions. When you call this label on a page, the encapsulated function is called, these labels can output content on the page, query the database, and process XML documents. The jstl tag library can basically be divided into five categories, includes the jstl core library, database tag library, XML operation tag library, international and format tag library, and function tag library. The core jstl library includes basic input/output, process control, and loop functions. The database tag library mainly includes basic database operation functions. The XML operation tag library is used to process XML documents; the internationalization and format tag library mainly serves to standardize internationalization and text formats.
By using these tags, you can basically avoid using Java code on the page. These labels are very powerful and only introduce a simple tag, you can implement the functions that can be implemented by a large Java segment on the JSP page. This not only avoids repeated coding, but also facilitates program modification and maintenance.
Common labels
Output tag <C: Out/>:
Code
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8 "pageencoding =" UTF-8 "%> <% @ taglib prefix =" C "uri =" http://java.sun.com/jsp/jstl/core "%> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> <HTML>
Running result
Judgment tag <C: If/> and <C: Choose/>, <C: When/>, <C: otherwise>:
Code
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8 "pageencoding =" UTF-8 "%> <% @ taglib prefix =" C "uri =" http://java.sun.com/jsp/jstl/core "%> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> <HTML>
Running result
Code
<% @ Page Language = "Java" contenttype = "text/html; charset = UTF-8 "pageencoding =" UTF-8 "%> <% @ taglib prefix =" C "uri =" http://java.sun.com/jsp/jstl/core "%> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> <HTML>
Running result
Loop tag <C: foreach/>:
Code
<% @ Page Language = "Java" Import = "Java. util. * "contenttype =" text/html; charset = UTF-8 "pageencoding =" UTF-8 "%> <% @ taglib prefix =" C "uri =" http://java.sun.com/jsp/jstl/core "%> <! Doctype HTML public "-// W3C // dtd html 4.01 transitional // en" "http://www.w3.org/TR/html4/loose.dtd"> <HTML>
Running result
What jstl thinks
Nested Java code in JSP is for the convenience of the development interface. If JSP is not used, it can only output HTML elements in a very troublesome way. jstl replaces Java code for the convenience of Java code development, it can be understood as a form of decoupling (separating Java code from HTML elements ).The previous approach is to combine the two technologies. The latter is to combine them organically, which is obviously more suitable for efficient development.. The final result is to improve code reusability. The universal code is written to the tag library and can be used directly next time. This is an excellent embodiment of Object-oriented thinking!