• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Unable to access ArrayList values from JSP

 
Ranch Hand
Posts: 243
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...
 
reply
    Bookmark Topic Watch Topic
  • New Topic