Let us assume that we have to display a number of fields in a table view
from the database. This will need iteration through the result set which
should be done using java code in your JSP pages or use of JSTL tags.
Struts gives you a ready made tag library called logic for
this kind of display logic.
Lets modify our login program to learn about logic tag library.
We will modify this proram to list all the users in the database. Add
more users to the database though your SQL client.
Create a new bean UsersVO, also called the value object by
some programmers which will be a place holder for the names retrieved
from the database.
package com.salsa;
import java.io.Serializable;
public class UsersVO implements Serializable{
private String userName;
public String getuserName() {
return userName;
}
public void setuserName(String user) {
userName = user;
}
}
Add the code to get user names from the data base upon successful login..
Statement statement=conn.createStatement();
rs = statement.executeQuery("SELECT USER_NAME FROM CMS_USER");
Add these resultset values an ArrayList
List userList = new ArrayList(20);
while(rs.next()) {
String userName = rs.getString(1);
System.out.println("user:"+userName);
UsersVO users = new UsersVO();
users.setuserName(userName);
userList.add(users);
}
Set the ArrayList as request attribute so that it can be accessed from the
JSP page.