Jstl Tag Library (1) Core Tag Library

Source: Internet
Author: User
Tags control label expression tld

Jstl Tag Library

The use of the JSTL tag library is created for the class to make up for the lack of HTML tables and to standardize the use of custom tags. After the farewell mode development application, people began to pay attention to the layered design of the software, do not want to appear in the JSP page Java logic code, but also because of the development of custom labels more difficult and unfavorable to technical standardization produced a custom tag library.

The JSTL tag library can be grouped into 5 categories:

(1). Core Tag Library

(2). I18N Format Tag Library

(3). SQL Tag Library

(4). XML Tag Library

(5). function Tag Library

1. Core Tag Library

Jstl's core tag library has a total of 13 tags, from the functional can be divided into 4 categories: the expression control tag, process control tag, loop tag, url operation tag. Use these tags to complete the basic functions of JSP pages, reduce coding work.

(1) The expression control tag: Out label, set label, remove label, catch tag.

(2) Process Control tag: If label, choose Label, when label, otherwise label.

(3) Circular label: foreach label, Fortokens label.

(4) URL Action tag: import tags, url tags, redirect tags.

<%@ taglib%> introduced tag library

1, in Classpath, add jar package: Standard-1.1.2.jar, Jstl-1.1.2.jar

2, in the photo-\web-inf\tld\ folder into the commonly used TLD file: c.tld,fmt.tld

3, in the JSP page to introduce the core tag library code:

<%@ taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>

1.1-expression Control label

The expression control category includes <c:out>, <c:set>, <c:remove>, and <c:chtch>4 tags, and now describes their functions and syntax respectively.

1.1.1<c:out> Label: "function": used to display the contents or results of a data object (a string, an expression).

The use of Java script output is often used in the following ways:

<% out.println ("string")%>

<%= expression%>

In web development, to avoid exposing the logical code to minimize the Java script in the page, use <c:out> tags to achieve these functions.

<c:out value= "string" >

<c:out value= "El expression" >

Hint: the use of Jstl and El expression is inseparable, El expression although you can directly return the results to the page, but sometimes the result is empty,<c:out> has a specific result processing function,

The use of El alone reduces the readability of the program, and it is recommended that the result input of El be placed in the <c:out> label.

There are two grammatical formats for the use of <c:out> labels.

"Syntax 1": <c:out value= "Data Objects to display" [Escapexml= "True|false"] [default= "Default"]>

"Syntax 2": <c:out value= "Data Objects to display" [escapexml= "True|false"]> default value </c:out>

There is no essential difference between these two ways, but the differences in format. The properties of the label are described below.

Value: Specifies the variable or expression to output.

EscapeXML: Sets whether to convert special characters (such as &lt, &GT, and other escape characters) directly in the output &LT if the default value is true, and if instead false will escape output "<".

Default: Results are output as defaults. If the result of using an expression is null (note that it differs from the null), the default result will be output.

1.1.2<c:set> Tags: "features": mainly used to access variables in the JSP scope or JavaBean properties.

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.