Java Jstl Tags

Source: Internet
Author: User
Tags control label

Transferred from: http://blog.csdn.net/liushuijinger/article/details/9143793

The JSTL (JSP standard tag Library, JSP standards tag libraries) is a custom tag library set that implements common features commonly found in Web applications, including iterative and conditional judgments, data management formatting, XML operations, and database access.

At present, there are many people using JSTL, today we will study together Jstl core label.

The code for introducing the core tag library on the JSP page is: <%@ taglib prefix= "C" uri= "Http://Java.sun.com/jsp/jstl/core"%>

Here's a brief look at the use of these tags:

1, Expression control label

<c:out>

Used to display data in a JSP.

Syntax 1: No ontology (body) content
<c:out value= "Value" [escapexml= "{true|false}"] [default= "DefaultValue"]/>


Syntax 2: Ontology content
<c:out value= "Value" [escapexml= "{true|false}"]>
Default value
</c:out>

<c:set>

Used to save data.

Syntax 1
The value is stored in the varname variable of scope:
<c:set value= "value" var= "VarName" [scope= "{page|request|session|application}"]/>


Syntax 2
Store the data of the ontology content into the varname variable of scope:
<c:set var= "VarName" [scope= "{page|request|session|application}"]>
... Ontology content
</c:set>

Syntax 3
The value is stored in the properties of the target object:
C:set value= "value" target= "target" property= "PropertyName"/>

Syntax 4
Store the data of the ontology content into the properties of the target object:
<c:set target= "target" property= "PropertyName" >
... Ontology content
</c:set>

<c:remove>

Used to delete data.

Grammar:
<c:remove var= "VarName" [scope= "{page|request|session|application}"]/>

<c:chtch>

2, Process Control label

<c:if>

Use is similar to if in other languages.

Syntax 1
: No ontology content (body)
<c:if test= "testcondition" var= "VarName" [scope= "{page|request|session|application}"]/>
The varname value is the Testcondition execution result (boolean value).


Syntax 2
: Has ontology content
<c:if test= "Testcondition" [var= "VarName"] [scope= "{page|request|session|application}"]>
Ontology Content </c:if>
If the result of the expression is true, the ontology content is executed, and false is the opposite

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

These 3 tags are typically used together with the,<c:choose> tag as the parent tag for the <c:when> and <c:otherwise> tags.

Syntax 1:
<c:choose>
<c:when>
An expression
<c:otherwise>
An expression
<c:otherwise>
An expression
</c:choose>

Syntax 2:
<c:when text= "Conditions" >
An expression
</c:when>


Syntax 3:
<c:otherwise>
An expression
</c:otherwise>

Add:

(1) Syntax 1 is a nested use of 3 tags,<c:choose> tags can only be used in conjunction with <c:when> tags.
(2) Syntax 2 is the use of <c:when> label, the label is judged by the conditions, generally and <c:choose> common use.
(3) <c:otherwise> does not contain parameters, can only be used in conjunction with <c:when>, and only allowed to occur once in nesting.

3, Loop label

<c:forEach>

Similar to foreach in other languages.

Syntax: Iterate over all members of a collection object
<c:foreach [var= "VarName"] items= "collection" [varstatus= "Varstatusname"]
[begin= "Begin"] [end= "End"] [step= "Step"]>
</c:forEach>

<c:forTokens>

Used to browse the string and intercept the string based on the specified character.

Grammar:
<c:fortokens items= "Strigoftokens" delims= "" delimiters [var= "name" begin= "Begin" end= "End" step= "Len" varstatus= " Statusname "] >

4,url Operation label

<c:import>

This tab can include other static or dynamic files in this JSP page. The difference with <jsp:include> is that only files in the same web app can be included. <c:import> can include files from other web apps, even resources on the network.

Syntax 1:
<c:import url= "url" [context= "context"] [value= "value"][scope= "page|request|session|application"] [charencoding = "Encoding"]>


Syntax 2:
<c:import url= "url" varreader= "name" [context= "Context"][charencoding= "encoding"]><c:redirect>

<c:url>

This tag is used to dynamically generate a string-type URL that can be used in conjunction with the <c:redirect> tag, or you can use the HTML <a> tag to implement hyperlinks.

Syntax 1: Specifies that a URL is not modified, you can choose to store the URL in a different range of JSPs.
<c:url value= "Value" [var= "name"][scope= "page|request|session|application"][context= "context"]/>


Syntax 2: Adds the specified parameter and parameter value to the URL, optionally storing the URL in name.
<c:url value= "Value" [var= "name"][scope= "page|request|session|application"][context= "context"]>
<c:param name= "parameter name" value= "Value" >
</c:url>

It says so much, so why use Jstl? What advantages does it have? The advantages are as follows:
1. Simplifies the development of JSP and Web applications.
2, easy to maintain.
3, reduce or even avoid the JSP in the Scriptlet code.
4, easy to master the front desk personnel, so that the division of labor clear, improve team development efficiency.

Some people say that jstl is outdated, in fact, each language has its advantages, there is no outdated and not outdated, it is not appropriate to see fit. The specific choice of what to look at the company requirements and the actual situation of the project.

Java Jstl Tags

Related Article

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.