Use the JSTL foreach and if when labels.

Source: Internet
Author: User

Use the JSTL foreach and if when labels.

Add the following tag library and function library to jsp

<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %> // required <% @ taglib uri = "http://java.sun.com/jsp/jstl/fmt" prefix = "fmt" %> // some formatting is required parameter, not Required

<% @ Taglib prefix = "fn" uri = "http://java.sun.com/jsp/jstl/functions" %> // the function to be used when processing data, not required

 

 

1. Traverse list <Object>

<C: forEach items = "$ {list}" var = "list" varStatus = "status">

$ {List. name}

</C: forEach>

 

2. Traverse list <String>

<C: forEach items = "$ {optList}" var = "optList" varStatus = "status">

$ {OptList}

</C: forEach>

 

3. Traverse list <Map <String, String>

<C: forEach var = "name" items = "$ {a}"> <c: forEach var = "entry" items = "$ {name}"> <c: out value = "$ {entry. key} "/> <c: out value =" $ {entry. value} "/> </c: forEach>

 

4. Traverse map

<C: forEach items = "$ {map}" var = "mymap"> <c: out value = "$ {mymap. key} "/> <c: out value =" $ {mymap. value} "/> </c: forEach>

 

5. if

Add

<c:if test="${salary > 2000}">   <p>My salary is: <c:out value="${salary}"/><p></c:if>

6. choose tag

<C: choose>

<C: when test = "$ {param <= 2}">

1 </c: when>

<C: when test = "$ {param >=2}">

2 </c: when> <c: otherwise>

$ {Param}

</C: otherwise> </c: choose>

Java enterprise-level general permission security framework source code SpringMVC mybatis or hibernate + ehcache shiro druid bootstrap HTML5

[Download java framework source code]

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.