JAKARTA STRUTS Programming Learning: Tags -> Logic-> Iterate

zhaozj2021-02-11  154

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);

%>

Name:

Password:

Put user.class, iateate.jsp in the corresponding directory, run iterate.jsp You can see the effect of Iterate.

The iTerate tag ID is its label, name is used to match the corresponding session or other properties, Type is the type of collected elements in it.

The BEAN's WRITE tag is used to output the attribute output, name to match the iTerate ID, which is used to match the corresponding class properties

My contact details baichenhong@hotmail.com, welcome everyone to criticize.

转载请注明原文地址:https://www.9cbs.com/read-5336.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.044, SQL: 9