• Post Reply Bookmark Topic Watch Topic
  • New Topic

Unable to access ArrayList values from JSP  RSS feed

 
Vijay Vaddem
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 243
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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...
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!