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

1
  • 1
    I've already answered this in one of your previous questions: stackoverflow.com/questions/6168836/… Just replace <select> by <table> and <option> by <tr><td>. Commented Jun 2, 2011 at 4:24

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.