File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
JavaRanch » Java Forums » Java » JSP
Bookmark "Unable to access ArrayList values from JSP " Watch "Unable to access ArrayList values from JSP " New topic
Author

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 page.....it is not returning the values......the size indicates 0.
When i add a main method to the bean and retrieve the values....it 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 {
Class.forName("org.gjt.mm.mysql.Driver");
}catch (ClassNotFoundException e) {
System.out.println("Exception in Driver::" + e);
}

try {

con=DriverManager.getConnection("jdbc:mysql://localhost/timesheet","root","");
stmt = con.createStatement();
rs=stmt.executeQuery(query);

while (rs.next())
{

String temp=rs.getString(1);
usernames.add(temp);
System.out.println("Size:"+usernames.size());






} //end of while

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


return usernames;

} // end of get method...

/*public void setNames(Vector usernames1)

{
this.usernames=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???
tx...
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Unable to access ArrayList values from JSP