Introduction to common JSTL tag libraries, jstl tag Libraries

Source: Internet
Author: User
Tags control label

Introduction to common JSTL tag libraries, jstl tag Libraries
Recently, JSTL labels are often used in development, which is quite useful. Here we will introduce several common JSTL labels for your reference. Let's review and review your knowledge!

The first is the if in the process control label, which is used a lot. Specific statement:

<C: if test = "condition"> execution statement </c: if>
For example, if condition 1 is true, a button is displayed, and if condition 2 is true, a hyperlink is displayed:

<C: if test = "condition 1"> <input id = "submit_btn" class = "btn-primary" type = "submit" value = "submit"/> </c: if> <c: if test = "condition 2"> <a href = "http://www.baidu.com" target = "_ blank"> Baidu </a> </c: if>
If you want to make a logical judgment, use and or. This is different from the & | in java. At first, I thought it was java and later I knew it was not.
So if there are multiple conditions, can we judge it like if elseif else in java? The answer is OK:

Use <c: choose> </c: choose> to set <c: when test = ""> </c: when> to judge multiple statements.

<C: choose> <c: when test = "$ {score >=90}"> your score is excellent! </C: when> <c: when test = "$ {score> = 70 and score <90}"> your score is good! </C: when> <c: when test = "$ {score> 60 and score <70}"> your score is pass </c: when> <c: otherwise> sorry, you have not passed the test! </C: otherwise> </c: choose>
The Process Control label is finished. Here is a forEach.

Here, allProducts is a collection of products, which contains many products. Each element in the product is cyclically stored in the checkbox to achieve the multi-choice box effect.
<c:forEach var="product" items="${allProducts}">    <label class="checkbox inline">        <input type="checkbox" name="productId" value="${product.id}">${product.name}    </label></c:forEach>
<C: forEach> you can add varStatus = "idx" to the label, and then you can make judgments in it, for example, $ {idx. index> 0} or $ {idx. index ++}
Gets the length of a list set. You can use the fn function.

To import tags: <% @ taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions" %>

${fn:length(product.selllingPoints)} 





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.