JSTL foreach and if when labels are used

Source: Internet
Author: User

You need to include the following tag libraries and libraries in your JSP

<%@ taglib uri= "Http://java.sun.com/jsp/jstl/core" prefix= "C"%>//must <%@ taglib uri= "http://java.sun.com/jsp /jstl/fmt "prefix=" FMT "%>//need to format some parameters when used, not required

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

1. Traversing list< objects >

<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> </c:forEach>

4. Traverse the Map

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

5.if use

First, add in the JSP

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

6.choose Label

<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-Class generic rights security framework source SPRINGMVC MyBatis or Hibernate+ehcache Shiro Druid Bootstrap HTML5

"Java Framework source code download"

JSTL foreach and if when labels are used

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.