File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Struts and the fly likes Display ArrayList data on jsp page Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Display ArrayList data on jsp page" Watch "Display ArrayList data on jsp page" New topic

Display ArrayList data on jsp page

sona aia

Joined: Mar 29, 2005
Posts: 5
Hi all ,
I am collecting a list of data from my database in my Action Class and populating it in an ArrayList viz "a" . Total I have 2 ArrayList's . one for storing EmployeeBean objects and other which stores (multiple)project names for each employee.

/*Here I am Storing Multiple Project Names under a single Employee */
Hashtable h = new Hashtable();

String [] param = {rs.getString("empid")};
h.put((String) rs.getString("empid"),new ArrayList());
if(h.containsKey((String) rs.getString("empid")))
ArrayList a = (ArrayList) h.get((String) rs.getString("empid"));
a.add(new String(rsProj.getString("p.projname")));
/*Here I am storing each employee's data in a Bean */
ArrayList empList = new ArrayList();
try {
while (!rs.isAfterLast()) {
EmployeeBean pb = new EmployeeBean();
ArrayList a = (ArrayList) h.get((String)rs.getString("empid"));

pb.setProjName(a); /*Store multiple proj names */
request.setAttribute("empList", empList);

My EmployeeBean is as follows :

public class EmployeeBean {
private String empId;
private String empName;
private ArrayList projName;

public String getEmpId() {
return empId;

public void setEmpId(String empId) {
this.empId = empId;

public String getEmpName() {
return empName;

public void setEmpName(String empName) {
this.empName = empName;

public ArrayList getProjName() {
return projName;

public void setProjName(ArrayList projName) {

Now i have to display this entire information for each employee in a table. So i have created a jsp page for tht.

<c:forEach items="${empList}" var="empItem">
<tr width="100%" >
<td align="center" width="50">
<c ut value="${empItem.empId}" />
</td >
<td align="center" width="123px">
<c ut value="${empItem.empName}" />
<td align="center" width="145px">

<html:select name="empList" property="empList">
<html ptions collection="empList.projName" labelName="empList.projName"/>

Now , I am stuck with how to display the data stored in the ArrayList "projName" . Can anyone solve my problem ???

Lijo Jacob

Joined: Sep 02, 2004
Posts: 5
Here is an example:

I have a Java Bean by name Paper with the following instance variables:
int paper_id
String short_nm

And from some part of the code, an ArrayList having objects of the Paper bean is put in the session scope (by the name 'papers').

Now if I want to use the paper_ids of the objects in the ArrayList to populate a select box then:

<c:set var="papers" value="${sessionScope.papers}" />

<html:select size="1" property="newPaper" value="${spp.newPaper}" >

<html ption value="0">Select Paper</html ption>
<html ptions collection="papers" property="paper_id" labelProperty="paper_id" />


Lijo Jacob<br />SCJP, SCWCD, SCBCD
P. Ingle
Ranch Hand

Joined: Apr 25, 2005
Posts: 45
"<c:set var="custList" value="${RequestScope.custList}" />"

what kind of tag is this?

Thanks,<br />P.Ingle
Lijo Jacob

Joined: Sep 02, 2004
Posts: 5
Its a JSTL tag
I agree. Here's the link:
subject: Display ArrayList data on jsp page
It's not a secret anymore!