C:foreach,c:if Label Summary of Jstl label

Source: Internet
Author: User

The <c:forEach> tag is used for general data loops and has the following properties

Properties Description Whether you must Default value
Items Projects that are looping Whether No
Begin Start condition Whether 0
End End condition Whether The last item in the collection
Step Step Whether 1
Var Represents the variable name of the current project Whether No
Varstatus Variables that show the loop state Whether No

Begin and End Properties

You can specify the start loop position and the end loop position. For example

Start the iteration from the second element of the collection:

<c:foreach items= "${userinfo.roletypeennames}" var= "Item" varstatus= "status" begin= "1" ></c:forEach>

Iterate from the first element of the collection, end of the second element

<c:foreach items= "${userinfo.roletypeennames}" var= "Item" varstatus= "status" begin= "0" end= "1" ></c:foreach >

Vastatus Property

like the Varstatus and Var properties in Jstl, varstatus is used to create scoped variables. However, a variable named by the Varstatus property does not store the current index value or the current element, but instead assigns an instance of the Javax.servlet.jsp.jstl.core.LoopTagStatus class. The class defines a set of attributes that describe the current state of the iteration, which are listed below:

The attribute         Getter                       describes    the current getcurrent ()           item in this iteration (in the collection)       index GetIndex ()               the current iteration from 0 for the iteration indexes count       GetCount ()             the iteration count of the current iteration starting at 1 first          IsFirst ()                  is used to indicate whether the current iteration is the first iteration of the flag last          islast ()                  A flag that indicates whether the current iteration is the last iteration, begin      Getbegin ()             Begin property Value End         getend ()                 End Property value Step        getstep ()                Step Property value

The properties of Vastatus in C:foreach can be used to obtain the state of an iteration, such as:
<C:foreach var= "" items= "" varstatus= "status" >
<c:out value= "${status.current}"/> Current object
<c:out value= "${status.index}"/> Index of this iteration
<c:out value= "${status.count}"/> Number of iterations
<c:out value= "${status.first}"/> is the first iteration of the object
<c:out value= "${status.last}"/> is the last iteration object
</c:foreach>

The Items property of the <c:forEach> tag supports all the standard collection types provided by the Java platform. In addition, you can use this action to iterate over the elements in an algebraic group, including an array of primitive types. The type of collection it supports and the elements of the iteration are as follows:

Java.util.Collection: Call iterator () to get the element.

Java.util.Map: an instance obtained through Java.util.Map.Entry.

Java.util.Iterator: iterator element.

Java.util.Enumeration: Enumeration element.

An object instance array: An array element.

An array of primitive type values: wrapped array elements.

A string delimited by commas: the segmented substring.

Javax.servlet.jsp.jstl.sql.Result:SQL the rows obtained by the query.

Invincible Split Line ****************************************

The <c:if> tag has the following properties:

Properties Description whether it is necessary Default Value
Test Conditions Is No
Var Variables for storing conditional results Whether No
Scope Scope of the Var attribute Whether Page

Example: Determine if Item contains LEDCDISTRICTMNG

<c:if test= "${fn:contains (item, ' LEDCDISTRICTMNG ')}" >
<tsp:show value= "Zxjx.createandrecommendcourse" >
<div class= "Mlr25 schb-btns" >
<a href= "${ctx}
Onlineteaching/course/coursestudy_coursestudyrecords.action?userid=${userinfo.userid}&flag=0 "
class= "Begin" ><span class= "Begin-ic" > Learned courses </span>

</a>
<a href= "${ctx}onlineteaching/teacrecourse_crecoursesteptwo.action?type=3" class= "recom" >

<span class= "Recom-ic" > Release course
</span>

</a>
</div>
</tsp:show>
</c:if>

Since only <c:if> does not have <c:else>, C:else can be replaced by the following methods:

<c:choose>
<c:when test= "${fn:contains (item, ' LEDCDISTRICTMNG ')}" >

111111
</c:when>
<c:otherwise>

222222
</c:otherwise>

</c:choose>

C:foreach,c:if Label Summary of Jstl label

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.