The moose likes JSP and the fly likes Unable to access ArrayList values from JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Unable to access ArrayList values from JSP " Watch "Unable to access ArrayList values from JSP " New topic

Unable to access ArrayList values from JSP

Vijay Vaddem
Ranch Hand

Joined: Feb 13, 2004
Posts: 243
Hi all,

My problem is like this...........
I have a bean class which returns a ArrayList( infact, i tried Vector as well) object with a set of values...when i try to retrieve these values in a JSP is not returning the values......the size indicates 0.
When i add a main method to the bean and retrieve the is displaying all the values....when i add a String value to the arraylist
and access it in JSP, it is displaying the value. So, My assumption is
somewhere im doing a mistake in accessing the object from JSP......
pls help me........the corresponding code is as follows::
Bean class:
package biz.vital.products.timesheet.bean;
import java.sql.*;
import java.util.ArrayList;
public class ApproverUserViewFormList

//Vector usernames =null;
public ArrayList usernames =null;

public ArrayList getNames()

Connection con=null;
ResultSet rs=null;
Statement stmt=null;
String query = "select empId from employee";
//usernames =new ArrayList();
usernames=new ArrayList();

try {
}catch (ClassNotFoundException e) {
System.out.println("Exception in Driver::" + e);

try {

stmt = con.createStatement();

while (

String temp=rs.getString(1);

} //end of while

} catch(SQLException e){
System.out.println("Exception in sql::" + e);
} finally {
}catch(Exception e) {
}// end of finally...

return usernames;

} // end of get method...

/*public void setNames(Vector usernames1)


public static void main(String ar[])
ApproverUserViewFormList auv = new ApproverUserViewFormList();
System.out.println("main size " +auv.getNames().size());


JSP code

<jsp:useBean id="list" scope="session" class="biz.vital.products.timesheet.bean.ApproverUserViewFormList"/>
<% Vector v1=list.getNames();
out.println("Vector v1 size :" + v1.size());
Vijay Vaddem
Ranch Hand

Joined: Feb 13, 2004
Posts: 243
I really wonder whats happening.....
i executed the same code without any change on another system and it worked
fine..........what could be the problem with my system???
I agree. Here's the link:
subject: Unable to access ArrayList values from JSP
It's not a secret anymore!