JSP Loop Cache List

Source: Internet
Author: User

Two methods:

For example, there are drop-down boxes

<select></select> where the options need to be displayed cyclically

1.JAVA Code Loop

<%

for (int i=0;i<list.size (); i++) {

Vo = List.get (i);

%>

<option value= "<%=vo.id%>" <%if (id==vo.id) {out.print ("selected")}%>><%=vo.id%></ Option>

<%

}

%>

2.JSTL Cycle

First, you need to introduce the JSTL source file in the JSP file: <% @taglib prefix= "C" uri= "Http://java.sun.com/jsp/jstl/core"%>

<c:if test= "${empty list}" >

Where the status of Varstatus= "status" equals I, is the index value

<c:foreach item= "${list}" vars= "Vo" varstatus= "status" >

where if the vo.id== "0", equals the value can be a JS variable, not a Java variable

<option value= "${vo.id}" <c:if test= "${vo.id=" 0 "}" >selected</c:if>>${vo.name}</option>

</c:foreach>

</c:if>

As in Method 2, if the vo.id== "0" in the judgment, the value is equal to the Java variable, so it is using method one

JSP Loop Cache List

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.