0

I am new to servlets and JSP. I have a table in my JSP page and I want to get all the values by using a for loop and then save. I am unable to loop through the data in a table by tag names in the servlet and I only get the first td value of the table. I don't know where I made a mistake.

Here is my code:

<table class="table table-hover" id="attendanceTableId">
    <%for(int i=0;i<=se.size()-1;i++) {%>
        <tr>
            <td><input type="textbox" name="studentName"  value="<%=se.get(i)%>" readonly></td>
            <td><input type="checkbox" name="status" value="present" style="width:15px;height:15px;"/>Present</td>
            <td><input type="checkbox" name="status" value="absent" style="width:15px;height:15px;">Absent</td>
        </tr>
    <%} %>
</table>

And servlet is:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    String rowCount=request.getParameter("rowCountHidden");
    int rowCountNum=Integer.parseInt(rowCount);
    System.out.println("rocount is"+rowCountNum);

    for (int i=1;i<=rowCountNum;i++) {
        String date=request.getParameter("date");
        String StudentName=request.getParameter("studentName");
        String status=request.getParameter("status");

        System.out.println("rocount is"+StudentName);
    }
}
dnvsp
  • 191
  • 1
  • 14
  • Duplicate: http://stackoverflow.com/q/35614753 – BalusC Jun 01 '16 at 11:02
  • //I tried like below and i got expected output.for (int i = 0; i <= rowCountNum - 1; i++) { String status[] = new String[rowCountNum]; status[i] = request.getParameter(Integer.toString(i)); System.out.println("status is :" + i + "," + status[i]); } – dnvsp Jun 06 '16 at 05:19

0 Answers0