JSP-10-JSTL Standard Tag Library

Source: Internet
Author: User
Tags i18n

The JSTL (JSP standard tag library) contains a standard set of tags for writing and developing JSP pages that provide users with a script-free environment.

JSTL provides 4 main tag libraries: Core Tag library, internationalization (i18n) and formatted tag library, XML tag library, and SQL tag library.

1 Core Tag Library

Pros: You can view the source code

The universal tag in the core tag library is used to manipulate the range variables created by the JSP page. The conditional tags are used to conditionally judge the code in the JSP page, and the two iteration tags are used to iterate through a collection of objects.

Ø Universal Label <c:set>:

This is a variable in the Web page, and if the variable does not exist, create it

<c:set var= "UID" value= "value" scope= "Page/request/session/application"/>

<c:remove>

Used to delete the created variable

<c:remove var= "varname" scope= "Page/request/session/application"/>

<c:out>

Evaluates the expression result and stores the result in the current JspWriter object

<c:out value= "value" escapexml= "True/false" default= "Defalutvalue"/>

which

Value: Refers to an expression

EscapeXML: Determines whether characters in the results (such as > < &, etc.) should be converted to character instance code, with the default value true;

Default: Defaults (if the result value is null)

Ø condition Label <c:if>

<c:if test= "condition" var= "VarName" scope= "Page/request/session/application" >

Body Content

</c:if>

which

Test: Specify conditions

The name of the variable that var:test the condition

Scope: Specify the range of Var

<c:choose>

Similar to Swich statements in Java

<c:choose>

<c:when test= "Condition 1" >

Method Body 1

</c:when>

<c:when test= "Condition 2" >

Method Body 2

</c:when>

<c:otherwise>

Method Body 3

</c:otherwise>

</c:choose>

Ø Iterative Labeling <c:forEach>

Used to repeat nested tag body contents in a collection of true individual objects

<c:foreach var= "VarName" items= "conllection" varstatus= "Varstatusname" begin= "begin" End = "End" >

Body Content

</c:forEach>

which

var: Specifies the name of the exported range variable

Items: Specifying a collection of objects to traverse

Varstatus: Specifies the name of the range variable for the traversal state.

Begin: Index to begin traversal

End: Index of ending traversal

<c:forTokens>

<c:fortokens items= "Stringoftoken" delims= "delimiters" var= "VarName" varstatus= "Varstatusname" >

Body Content

</c:forTokens>

which

Items: Values to traverse

Delims: Specifies the character used to delimit tokens in a string

var: Specifies the name of the range variable for traversing the object

Varstatus: Specifies the name of the range variable for the traversal state

2 internationalization and Format tag library

Internationalization (i18n) and the format tag library can be used to create internationalized Web applications that standardize the output of numbers and date-time.

<%@ taglib url= "Http://java.sun.com/jstl/fmt_rt" prefix= "FMT"%/>

<fmt:setLocale>

Used to override client-specified locale settings

<fmt:setlocale value= "setting" Variant= "Variant" scope= "Page/request/session/application"/>

which

Value: Contains a language code containing lowercase letters and a country code with two uppercase letters. Language and country codes should be delimited by hyphens or underscores.

Variant: Specifying browser-specific variables (optional)

<fmt:bundle>

Creates a i18n local context and loads its resource bundle into it. The name of the resource bundle is specified by the BaseName property of the <fmt:bundle> tag.

<fmt:bundle basename= "basename" >

Body Content

</fmt:bundle>

<fmt:message>

Used to give the output value of the resource bundle

<fmt:message key= "Messagekey"/>

<fmt:formatDate>

<fmt:formatdate value= "Date" pattern= "Yyyy-mm-dd HH:mm:ss"/>

JSP-10-JSTL Standard Tag Library

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.