how to retrieve the data using jstl from arraylist


Web tier: servlets, JSP, Web frameworks: how to retrieve the data using jstl from arraylist

  1. how to retrieve the data using jstl from arraylist (3 messages)

    Dear Sir, i have java class which retrieves the value from database and put it arraylist and i have jsp in that i am displaying data in a combo box from arraylist using jstl tag.But in the combo only last record is displaying.I am not able to find out where is the problem.. Below is the code snapshot: <%@ taglib uri="" prefix="c"%> <%@ page language="java" isThreadSafe="true" contentType="text/html;charset=UTF-8" autoFlush="true" import="java.util.*,java.sql.*,service.dbQueries" session="true" %> jstl JSTL Tag!! Categoty Name: "> ---------------------------------------------------------- Bean class ----------- package BO; import java.util.ArrayList; import service.dbQueries; public class categoryBO { private String id; private String catName; public ArrayList list; public ArrayList getList() { return list=new dbQueries().getData(); } public void setList(ArrayList list) { this.list = list; } public String getCatName() { return catName; } public void setCatName(String catName) { this.catName = catName; //System.out.println("\n\n\n the cat name is ......... "+catName); } public String getId() { return id; } public void setId(String id) { = id; } } -------------------------------------- Db class --------- package service; import java.sql.Connection; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; import java.util.ArrayList; import BO.categoryBO; import db.dbConnection; public class dbQueries { dbConnection db = new dbConnection(); Connection qConn=null; ResultSet rs=null; Statement stmt=null; public ArrayList getData() { ArrayList list =new ArrayList(); try { categoryBO catBo=new categoryBO(); qConn=db.getConnection(); stmt=qConn.createStatement(); //stmt = (Statement) db.getConnection(); String sql="select id, name from category"; rs=stmt.executeQuery(sql); while ({ //catBo.setId(rs.getString("id")); System.out.println(rs.getString("name")); catBo.setId(rs.getString("id")); catBo.setCatName(rs.getString("name")); //(catBo.setCatName(rs.getString("name"))); //setCatName(catName) list.add(catBo); //System.out.println(list.size().); } } catch (SQLException e) { // TODO Auto-generated catch block e.printStackTrace(); System.out.println("SQL error is : " + e.getMessage()); } catch (Exception ex) { // TODO Auto-generated catch block ex.printStackTrace(); System.out.println("Exception is : " + ex.getMessage()); } return list; } } ---------------------------------- Please do reply if anybody knows the answer. regards Subhashree
  2. Try this- Thanks, Vinod
  3. Dear Vinod, i tried with your piece of code but still it is not working. regards, Subhashree
  4. investigate[ Go to top ]

    Either "catlist" is not reachable or catlist.list is empty. In the first case you will see an exception in the console, in the second - nothing will be displayed. HND