Jakarta Struts Programming Learning: Tag àLogicàIterate
Iteerate is mainly used to deal with the output set class on the page, and the collection is generally one of the following:
1, array of Java objects
2, ArrayList, Vector, Hashmap, etc.
For specific usage, please refer to Struts-file, here is not described in detail
Now define a class, user.java compiles it into user.class
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 Password () {
Return (this. Password);
}
Public void setpassword (string password) {
THIS. Password = password;
}
}
Then create a JSP in a Struts WebApplication (see "Struts Attendance Experience"), 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 useera = 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.SetaTRibute ("List", LIST);
%>