0

I want to fetch rows from a mysql database using a servlet and display in an html table in a jsp. How can that be? some code if possible. just need the part of how the values are retrieved, how they are sent to the jsp and how the html table containing the values is generated? I want to display data from database via servlet to jsp but should be displayed in table format. Any help welcome

ken
  • 81
  • 1
  • 5
  • 12
  • 1
    I've already answered this in one of your previous questions: http://stackoverflow.com/questions/6168836/retrieve-dropdown-list-from-mysql-database-and-insert-to-database-in-jsp Just replace ` – BalusC Jun 02 '11 at 04:24

2 Answers2

1

While geting the data from the database,store that in the DTO(design pattern). and add that object to the arraylist. and return that arralist.now you just set this arraylist object in the setAttribute. in jsp you need to get this by using the getAttribute. Next you create the simple html table and using for loop you have to typecasting to dto class, and iterate this .you will see the data.

user902996
  • 11
  • 2
0

Sample code to do that

<% 
    Database db=new Database();
    ResultSet rsltst=db.stmnt.executeQuery("select univ_rollno,name from 6cs1;");
    %>
      <table>
        <th>Roll no</th>
        <th>Name</th>


<%
    while(rsltst.next()){
        %>
        <tr>
            <td><%=rsltst.getString("univ_rollno") %></td>
            <td><%=rsltst.getString("name") %></td>

        </tr>
        <%
    }
    rsltst.close();
    %>
    </table>
Rahul K Jha
  • 788
  • 9
  • 18