Home php教程 PHP开发 Usage of s:iterator

Usage of s:iterator

Dec 13, 2016 pm 05:31 PM
iterator

struts2’s s:iterator can traverse any array, collection, etc. in the data stack. Here are some simple demos:
s:iterator tag has 3 attributes:
value: the iterated collection
id: the element in the specified collection The id
status is the index of the iterated element

1:jsp page definition element writing array or list



A

The printed result is: 1A2A3A4A5A

2: Index usage
If specified status, each iteration data has an instance of IteratorStatus, which has the following methods

1: #status.odd Whether the current element index is an odd number of rows

2: # status.even Is the current element index even?
Line

3: #status.count How many elements are currently iterated
4: #status.index Current element index, starting from 0『#status.count=#status.index+1 』

5: #status.first Whether the current element is the first
6: #status.last Whether the current element is the last
7: #status.modules(int) Modulo the number of current rows



  Current index It is an odd number:

Current element value:

3: Traversing the map
value can be directly defined as:

value="#{"1":"a","2":"b"}"
Each element is separated by . The key and value between elements are separated by colons
value can also be the java.util.Map object in the data stack
The traversal is written as follows:


key :
value:

Of course both key and value You can use java's Object

3: traverse the data stack. Simple List class,
List
class Attr{String attrName;String getAttrName(){return "123";}}




Of course value can also be written as value="%{label}" label can have. The operation
label's attribute List can be written as value="%{label.list}" which is equivalent to: getLabel().getList();

4: Traverse 2 lists;
List attrN {color ,size,style}
List attrV {red,20,gay}
The elements of these two lists are one-to-one correspondence, one attrN corresponds to one attrV


index is :
attrName is : or
attrName is :


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
1 months ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Chat Commands and How to Use Them
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Java Iterator vs. Iterable: Demystifying the World of Iterators and Iterable Objects Java Iterator vs. Iterable: Demystifying the World of Iterators and Iterable Objects Feb 19, 2024 pm 02:15 PM

In Java programming, the Iterator and Iterable interfaces are important tools for processing elements in collections. The Iterator interface provides methods for iterative access to collection elements, while the Iterable interface defines the iterability of the collection so that the elements in the collection can be accessed through Iterator. The close cooperation between the two provides us with a general method for traversing collection elements. Iterator interface The Iterator interface defines the following methods: booleanhasNext(): Check whether there are still elements in the collection. Enext(): Returns the next element in the collection. voidremove(): Remove the current element. Iterable

Java Iterator vs. Iterable: A step into writing elegant code Java Iterator vs. Iterable: A step into writing elegant code Feb 19, 2024 pm 02:54 PM

Iterator interface The Iterator interface is an interface used to traverse collections. It provides several methods, including hasNext(), next() and remove(). The hasNext() method returns a Boolean value indicating whether there is a next element in the collection. The next() method returns the next element in the collection and removes it from the collection. The remove() method removes the current element from the collection. The following code example demonstrates how to use the Iterator interface to iterate over a collection: Listnames=Arrays.asList("John","Mary","Bob");Iterator

In-depth comparison of Java Iterator and Iterable: pros and cons analysis In-depth comparison of Java Iterator and Iterable: pros and cons analysis Feb 19, 2024 pm 04:20 PM

Conceptual differences: Iterator: Iterator is an interface that represents an iterator that obtains values ​​from a collection. It provides methods such as MoveNext(), Current() and Reset(), allowing you to traverse the elements in the collection and operate on the current element. Iterable: Iterable is also an interface, representing an iterable object. It provides the Iterator() method, which returns an Iterator object to facilitate traversing the elements in the collection. Usage: Iterator: To use Iterator, you need to first obtain an Iterator object, and then call the MoveNext() method to move to the next

Java Iterator and Iterable: The key to collection traversal, demystified Java Iterator and Iterable: The key to collection traversal, demystified Feb 20, 2024 am 10:27 AM

Introduction to IteratorIterator is an interface in Java for traversing collections. It provides a set of methods that allow you to access elements in a collection in a sequential manner. You can use Iterator to iterate over collection types such as List, Set, and Map. Demo code: Listlist=newArrayList();list.add("one");list.add("two");list.add("three");Iteratoriterator=list.iterator();while(iter

Java Iterator vs. Iterable: Unlocking the Power of Java Collections Java Iterator vs. Iterable: Unlocking the Power of Java Collections Feb 19, 2024 pm 07:00 PM

In Java, a collection is a collection of elements that provides a unified interface and methods to store, retrieve and operate these elements. Iterator and Iterable are two important Java interfaces that provide a common mechanism for traversing collection elements. The Iterator interface defines hasNext() and next() methods for traversing collections. The hasNext() method is used to check whether there are any untraversed elements in the collection, and the next() method is used to return the current element and move it to the next element. The Iterable interface defines the iterator() method, which returns an Iterator object for traversing the elements in the collection.

Java Iterator and Iterable: An in-depth analysis of Java collection traversal mechanism Java Iterator and Iterable: An in-depth analysis of Java collection traversal mechanism Feb 19, 2024 pm 08:36 PM

Iterator interface The Iterator interface is a low-level interface in the Java collection framework for traversing collections. It defines two main methods: hasNext(): checks if there are more elements in the collection. next(): Returns the next element in the collection. The Iterator interface also defines some optional methods, such as the remove() method, which is used to remove the current element from the collection. Using the Iterator interface You can use the Iterator interface to traverse a collection using the following steps: Get the Iterator object of the collection. Use the hasNext() method to check if there are more elements in the collection. If there are more elements, use the next() method to get the next element

Interpretation of Java documentation: Detailed explanation of the usage of iterator() method of HashSet class Interpretation of Java documentation: Detailed explanation of the usage of iterator() method of HashSet class Nov 03, 2023 am 09:44 AM

Interpretation of Java documentation: Detailed explanation of the usage of the iterator() method of the HashSet class. Specific code examples are required. In Java programming, HashSet is one of the commonly used collection classes. It implements the Set interface and inherits from the AbstractSet class. The iterator() method of the HashSet class is used to return an iterator object for traversing the elements in the HashSet. This article will explain in detail the usage of iterator() method of HashSet class, and

Java Iterator and Iterable: Behind the Scenes of Collection Traversal Java Iterator and Iterable: Behind the Scenes of Collection Traversal Feb 19, 2024 pm 04:15 PM

Iterator (Iterator) and Iterable object (Iterable) are two very important interfaces in the Java collection framework. They enable you to iterate over the elements in a collection without knowing the specific implementation of the collection. The Iterator interface defines methods for traversing collections, including hasNext() and next(). The hasNext() method checks if there are more elements in the collection, while the next() method returns the next element in the collection. The Iterable interface defines a method for creating an Iterator, the iterator() method. This method returns an Iterator object that can be used to iterate over the collection. The following is using Itera

See all articles