YouTip LogoYouTip

Jsp Jstl

The JSP Standard Tag Library (JSTL) is a collection of JSP tags that encapsulates common core functions for JSP applications. JSTL supports general, structured tasks such as iteration, conditional logic, XML document manipulation, internationalization tags, and SQL tags. In addition, it provides a framework for using custom tags integrated with JSTL. Based on the functionality provided by JSTL tags, they can be categorized into 5 types. * **Core Tags** * **Formatting Tags** * **SQL Tags** * **XML Tags** * **JSTL Functions** * * * ## JSTL Library Installation The steps to install the JSTL library on Apache Tomcat are as follows: Download the binary package (jakarta-taglibs-standard-current.zip) from the Apache Standard Tag Library. * Official download address: [http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/](http://archive.apache.org/dist/jakarta/taglibs/standard/binaries/) * Site download address: [jakarta-taglibs-standard-1.1.2.zip] Download the **jakarta-taglibs-standard-1.1.2.zip** package and extract it. Copy the two jar files, **standard.jar** and **jstl.jar**, from **jakarta-taglibs-standard-1.1.2/lib/** to **/WEB-INF/lib/**. Copy the required tld files from the tld directory to the WEB-INF directory. Next, add the following configuration to the web.xml file: http://java.sun.com/jsp/jstl/fmt/WEB-INF/fmt.tldhttp://java.sun.com/jsp/jstl/fmt-rt/WEB-INF/fmt-rt.tldhttp://java.sun.com/jsp/jstl/core/WEB-INF/c.tldhttp://java.sun.com/jsp/jstl/core-rt/WEB-INF/c-rt.tldhttp://java.sun.com/jsp/jstl/sql/WEB-INF/sql.tldhttp://java.sun.com/jsp/jstl/sql-rt/WEB-INF/sql-rt.tldhttp://java.sun.com/jsp/jstl/x/WEB-INF/x.tldhttp://java.sun.com/jsp/jstl/x-rt/WEB-INF/x-rt.tld To use any library, you must include the tag at the top of each JSP file. * * * ## Core Tags Core tags are the most commonly used JSTL tags. The syntax for referencing the core tag library is as follows: | Tag | Description | | --- | --- | | [](#) | Used to display data in JSP, similar to | | [](#) | Used to save data | | [](#) | Used to delete data | | [](#) | Used to handle exception conditions that produce errors and store the error message | | [](#) | Similar to the if statement used in regular programs | | [](#) | Acts only as a parent tag for and | | [](#) | A child tag of , used to judge whether a condition is met | | [](#) | A child tag of , executed after the tag when the tag evaluates to false | | [](#) | Retrieves an absolute or relative URL and exposes its content to the page | | [](#) | Basic iteration tag, accepts multiple collection types | | [](#) | Iterates over tokens separated by specified delimiters | | [](#) | Used to pass parameters to included or redirected pages | | [](#) | Redirects to a new URL. | | [](#) | Creates a URL with optional query parameters | * * * ## Formatting Tags JSTL formatting tags are used to format and output text, dates, times, and numbers. The syntax for referencing the formatting tag library is as follows: | Tag | Description | | --- | --- | | [](#) | Formats a number using the specified format or precision | | [](#) | Parses a string representing a number, currency, or percentage | | [](#) | Formats a date and time using the specified style or pattern | | [](#) | Parses a string representing a date or time | | [](#) | Binds a resource | | [](#) | Specifies the locale | | [](#) | Binds a resource | | [](#) | Specifies the time zone | | [](#) | Specifies the time zone | | [](#) | Displays resource configuration file information | | [](#) | Sets the character encoding of the request | * * * ## SQL Tags The JSTL SQL tag library provides tags for interacting with relational databases (Oracle, MySQL, SQL Server, etc.). The syntax for referencing the SQL tag library is as follows: | Tag | Description | | --- | --- | | [](#) | Specifies the data source | | [](#) | Runs an SQL query statement | | [](#) | Runs an SQL update statement | | [](#) | Sets a parameter in an SQL statement to a specified value | | [](#) | Sets a date parameter in an SQL statement to a specified java.util.Date object value | | [](#) | Provides nested database action elements within a shared database connection, running all statements as a single transaction | * * * ## XML Tags The JSTL XML tag library provides tags for creating and manipulating XML documents. The syntax for referencing the XML tag library is as follows: Before using XML tags, you must copy the relevant XML and XPath packages to your lib: * **XercesImpl.jar** Download address: [http://www.apache.org/dist/xerces/j/](http://www.apache.org/dist/xerces/j/) * **xalan.jar** Download address: [http://xml.apache.org/xalan-j/index.html](http://xml.apache.org/xalan-j/index.html) | Tag | Description | | --- | --- | | [](#) | Similar to , but only for XPath expressions | | [](#) | Parses XML data | | [](#) | Sets an XPath expression | | [](#) | Evaluates an XPath expression; if true, executes the body content, otherwise skips the body | | [](#) | Iterates over nodes in an XML document | | [](#) | Parent tag for and | | [](#) | Child tag of , used for conditional judgment | | [](#) | Child tag of , executed when evaluates to false | | [](#) | Applies an XSL transformation to an XML document | | [](#) | Used with to set the XSL stylesheet | * * * ## JSTL Functions JSTL includes a set of standard functions, most of which are common string processing functions. The syntax for referencing the JSTL function library is as follows: | Function | Description | | --- | --- | | [fn:contains()](#) | Tests whether the input string contains the specified substring | | [fn:containsIgnoreCase()](#) | Tests whether the input string contains the specified substring, case-insensitive | | [fn:endsWith()](#) | Tests whether the input string ends with the specified suffix | | [fn:escapeXml()](#) | Escapes characters that could be interpreted as XML markup | | [fn:indexOf()](#) | Returns the position of the specified string within the input string | | [fn:join()](#) | Joins the elements of an array into a single string and outputs it | | [fn:length()](#) | Returns the length of the string | | [fn:replace()](#) | Replaces occurrences of a specified string within the input string and returns the result | | [fn:split()](#) | Splits a string by a specified delimiter and returns an array of substrings | | [fn:startsWith()](#) | Tests whether the input string starts with the specified prefix | | [fn:substring()](#) | Returns a subset of the string | | [fn:substringAfter()](#) | Returns the substring after the first occurrence of the specified substring | | [fn:substringBefore()](#) | Returns the substring before the first occurrence of the specified substring | | [fn:toLowerCase()](#) | Converts the characters in the string to lowercase | | [fn:toUpperCase()](#) | Converts the characters in the string to uppercase | | [fn:trim()](#) | Removes leading and trailing whitespace |
← Jsp Database AccessJsp Sending Email β†’