how to display the contents of the database values which are retrived.

how to display the contents of the database values which are retrived in servlets and i am able to display the contents in the servlets and if forward to jsp using requestdespatcher,the values are to be shown in jsp one below the other.please suggest me in these........the servlet code is as shown

while(rs.next()){

buffer.append(rs.getString(1));

buffer.append(rs.getString(2));

buffer.append(rs.getString(3));

buffer.append(rs.getString(4));

buffer.append(rs.getString(5));

buffer.append(rs.getString(6));

buffer.append(rs.getString(7));

buffer.append(rs.getString(8));

buffer.append(rs.getString(9));

buffer.append(rs.getString(10));

request.setAttribute("result1",buffer);

RequestDispatcher rq=request.getRequestDispatcher("/results.jsp");

rq.forward(request,response);

in jsp iam using the getAttribute to retrieve the values as shown

<% StringBuffer sb=(StringBuffer)request.getAttribute("result1"); %>

<%= sb %>

but getting the results in the stretch,i need to display the result one below the other.

[1135 byte] By [manjuinfyreddya] at [2007-10-2 10:57:08]
# 1

if you load it all into the buffer that is going to be very difficult. I would suggest loading it into some sort of collection. I like using an ArrayList.

Then pass the arraylist.

you will then on the jsp iterate through the arrayList using what every you want.. el, logic tags, scriplets.

so something like

ArrayList arrayList = new ArrayList();

while(rs.next()){

arrayList.append(rs.getString(1));

....

....

//or possibly an arrayList of String arrays

//maybe using nested for loops. Inner for loop adds result to string[] then //outer adds string[] to arrayList.

//can be done any number of ways based on your expected result set.

gmachamera at 2007-7-13 3:23:15 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...