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);
}
}