JSTL, jstlchm

Source: Internet
Author: User

JSTL, jstlchm

Core tag Library

<C: out>Tags have the following attributes:

 

Property description required default value

The output content of value is none.

Default output default value NO content in the subject

Whether escapeXml ignores special XML characters or not

 

<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>  
 

<C: set>Tags have the following attributes:

 

Property description required default value

The value to be stored. No subject content

Target: the object to which the attribute to be modified belongs no

Whether the property to be modified is none

Is there any variable for var to store information?

Scope var attribute scope no Page

If the target attribute is specified, the property attribute also needs to be specified. You can modify the javabean object and Map object more often.

 

<C: remove>Tags have the following attributes:

 

Property description required default value

The name of the variable to be removed by var is none.

Scope to which the scope variable belongs: No. All scopes

 

<C: catch>Tag

 

<c:catch var="catchException">   <% int x = 5/0;%></c:catch> <c:if test ="${catchException != null}">   <p>The exception is :${catchException} <br />   There is an exception:${catchException.message}</p></c:if>

 

<C: if>Tags have the following attributes:

 

Property description required default value

The test condition is none.

The var variable used to store the condition result does not exist

Scope var attribute scope no page

 

<C: choose>, <c: when>, <c: otherwise> label

 

<c:set var="salary" scope="session" value="${2000*2}"/><p>Your salary is : <c:out value="${salary}"/></p><c:choose>    <c:when test="${salary <= 0}">       Salary is very low to survive.    </c:when>    <c:when test="${salary > 1000}">        Salary is very good.    </c:when>    <c:otherwise>        No comment sir...    </c:otherwise></c:choose>

 

<C: import>Tags have the following attributes:

 

Property description required default value

The url of the page to be retrieved and introduced is none.

Context/followed by a local network application name no current application

Character character set no ISO-8859-1 for data introduced by charEncoding

Var is used to store the variable "no Print to page" of the introduced text.

Scope var attribute scope no Page

VarReader (optional) specifies whether the variable that provides the java. io. Reader object is null.

 

<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %> 
 

The above program will print the http://www.w3cschool.cc page

 

<C: forEach>Tags have the following attributes:

 

Property description required default value

Does the information about the items to be recycled exist?

Element starting with begin (0 = first element, 1 = second element) No 0

End: Last element (0 = first element, 1 = second element) No Last element

Step: step No 1 for each iteration

Var indicates the name of the variable of the current entry. No

VarStatus indicates the variable name in the loop status.

 

<c:forEach var="i" begin="1" end="5">   Item <c:outvalue="${i}"/><p></c:forEach>

 

<C: forTokens>A tag has similar attributes to a <c: forEach> tag. However, <c: forTokens> has another attribute:

Delims separator is none

 

<c:forTokens items="Zara,nuha,roshy" delims="," var="name">   <c:out value="${name}"/><p></c:forTokens>
 

<C: forEach> the items in the tag is a collection class object or array, while the items in the <c: forTokens> tag is a string

 

<C: url>Tags have the following attributes:

Property description required default value

Value Base URL is none

Context Local Network Application name no current application

Var indicates whether the variable name of the URL is printed to page.

Scope var attribute scope no Page

 

<C: url> the tag formats the URL as a string and stores it in a variable. This label will automaticallyRewrite URL. The var attribute is used to store formatted URLs. Note: If the value does not start with "/", the URL will not be overwritten automatically.

<C: url> A tag is only an optional method for calling the response. encodeURL () method. Its real advantage is that it provides appropriate URL encoding, including the parameters specified in <c: param>.

 

 

<C: param>Tag

<c:url value="/index.jsp" var="myURL">   <c:param name="trackingId" value="1234"/>   <c:param name="reportType" value="summary"/></c:url><c:import url="${myURL}"/>

 

<C: redirect>The tag redirects the browser to a new URL by automatically rewriting the URL. It provides content-related URLs and supports the c: param tag.

Property description required default value

The target url is none.

Context followed by a local network application name no current application


Format tags

The JSTL format label is used to format and output text, date, time, and number.

Label description

<Fmt: formatNumber> Format a number with the specified format or precision

<Fmt: parseNumber> parses a string representing a number, currency, or percentage.

<Fmt: formatDate> Format the date and time in the specified style or mode.

<Fmt: parseDate> parses a string representing the date or time.

<Fmt: bundle> bind Resources

<Fmt: setLocale> Specified Region

<Fmt: setBundle> bind Resources

<Fmt: timeZone> specifies the time zone.

<Fmt: setTimeZone> specifies the time zone.

<Fmt: message> displays the resource configuration file information.

<Fmt: requestEncoding> sets the request character encoding.


SQL tag

The jstl SQL tag Library provides tags for interacting with relational databases (Oracle, MySQL, SQL Server, and so on.

Label description

<SQL: setDataSource> specifies the data source.

<SQL: query> run an SQL query statement

<SQL: update> run an SQL update statement

<SQL: param> set the parameters in the SQL statement to the specified value.

<SQL: dateParam> set the Date parameter in the SQL statement to the value of the specified java. util. Date object.

<SQL: transaction> provides nested database behavior elements in a shared database connection to run all statements in the form of one transaction.


XML tag

The jstl xml tag Library provides tags for creating and operating XML documents.

Before using the xml tag, you must copy the XML and XPath packages to your <Tomcat installation directory> \ lib:

Label description

<X: out> similar to <% =...>, but only used for XPath expressions

<X: parse> parse XML data

<X: set> set an XPath expression

<X: if> determines the XPath expression. if it is true, the content in the body is executed. Otherwise, the body is skipped.

<X: forEach> iterate nodes in XML documents

<X: choose> <x: when> and <x: otherwise> parent labels

<X: when> <x: choose> sub-tag used for condition Determination

<X: otherwise> <x: choose> is executed when <x: when> is set to false.

<X: transform> apply the XSL conversion to the XML document.

<X: param> and <x: transform> are used together to set the XSL style sheet.


JSTL Functions

JSTL contains a series of standard functions, most of which are common string processing functions.

Function Description

Fn: contains () test whether the input string contains the specified substring

Fn: containsIgnoreCase () test whether the input string contains the specified substring. It is case insensitive.

Fn: endsWith () test whether the input string ends with the specified suffix

Fn: escapeXml () skips characters that can be marked as XML characters

Fn: indexOf () returns the position where the specified string appears in the input string.

Fn: join () combines the elements in the array into a string and then outputs

Fn: length () returns the string length.

Fn: replace () replaces the specified position in the input string with the specified string and returns

Fn: split () separates the string with the specified separator and then forms an array of substrings and returns

Fn: startsWith () test whether the input string starts with the specified prefix

Fn: substring () returns the subset of the string.

Fn: substringAfter () returns the subset of the string after the specified substring.

Fn: substringBefore () returns the subset of the string before the specified substring.

Fn: toLowerCase () converts the characters in the string to lowercase letters.

Fn: toUpperCase () converts the characters in the string into uppercase letters.

Fn: trim () removes the leading blank character

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.