Struts programming learning-label logic: iterate

Source: Internet
Author: User
Tags tld

Struts programming learning-label logic: iterate

 

【Author】: Unknown <size: 1 k <Release Date: <browse: 4639 〗
 
Iterate is mainly used to process the output set class on the page. The set is generally one of the following:

1. array of Java objects

2. arraylist, vector, and hashmap

For details about the usage, refer to the struts document.

Now define a class, which is compiled into user. Class by user. java.

Package example;

Import java. Io. serializable;
Public final class user implements serializable {
Private string name = NULL;
Private string Password = NULL;

Public String getname (){
Return (this. Name );
}

Public void setname (string name ){
This. Name = Name;
}

Public String GetPassword (){
Return (this. Password );
}

Public void setpassword (string password ){
This. Password = password;
}

}

Create a JSP in a struts webapplication, such as iterate. jsp.

<% @ Page Language = "Java" %>
<% @ Page import = "example. *" %>
<% @ Taglib uri = "/WEB-INF/struts-bean.tld" prefix = "Bean" %>
<% @ Taglib uri = "/WEB-INF/struts-logic.tld" prefix = "logic" %>

<%
Java. util. arraylist list = new java. util. arraylist ();
User usera = new user ();
Usera. setname ("white ");
Usera. setpassword ("ABCD ");
List. Add (usera );
User userb = new user ();
Userb. setname ("Mary ");
Userb. setpassword ("hijk ");
List. Add (userb );
Session. setattribute ("list", list );

%>

& Lt; HTML & gt; & lt; Body & gt; & lt; table width = "100%" & gt;

<Logic: iterate id = "A" name = "list" type = "example. User">

& Lt; tr & gt; & lt; TD width = "50%" & gt;

Name: <Bean: write name = "A" property = "name"/>

& Lt; TD/& gt; & lt; TD width = "50%" & gt;

Password: <Bean: write name = "A" property = "password"/>

</TD> </tr>

</Logic: iterate>

</Table> </body>

Put user. Class, iterate. jsp to the corresponding directory. Run iterate. jsp and you will see the iterate effect.

Iterate flag
ID: the name of the script variable, which stores the handle of the current element in the set.
Name indicates the set to be stacked, from the attributes of the session or request.
Type is the type of the Collection class element.

The write tag of bean is used to output attributes. Name is used to match the iterate ID, and property is used to match the attributes of the corresponding class.
 

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.