I have a JSP page with a table containing data from java.util.List. The items from the list are taken from the database.

  • Each row has an edit button that will get all the values from that specific row to be edited on another page.
  • Each row has a checkbox where if selected means it will be deleted from the table. The "delete all" button at the end will do the batch delete.

I think I can do this very easily with nested forms, placing the update form inside the delete form and calling update form whenever an edit button is clicked. But since we are not aloud to do that, I created those forms separately instead and used HTML5's form attribute to refer to delete form.

Are there other, better ways of doing this, seeing that I can't do this in HTML4 for compatibility with older browsers, but I don't care about compatibility that much at this time. I just feel this code is too ugly. How can I improve my code?

<%@ include file="design/header.jsp" %>
    <h3>Reservation List</h3>
    <form id="delete" action="deletereservations.html" method="post"></form>
            <td>Check In Date</td>
            <td>Check Out Date</td>
            <td>Room Type</td>
            <td>Action-SELECT Delete</td>
        <c:forEach var="reservation" items="${reservations}"> 
                    <c:when test="${reservation.status eq 1}">
                    <c:when test="${reservation.status eq 2}">
                            <form action="updatereservation.html" method="post">
                                <input type="hidden" name="checkInDate" value="${reservation.strCheckInDate}">
                                <input type="hidden" name="checkOutDate" value="${reservation.strCheckOutDate}">
                                <input type="hidden" name="roomType" value="${reservation.roomType}">
                                <input type="hidden" name="id" value="${reservation.reservationID}">
                                <input type="image" src="images/edit.jpg" height="30" width="30"  value="edit">
                            <input type="checkbox" name="id" value="${reservation.reservationID}" form="delete">
                    <c:when test="${reservation.status eq 3}">
    <input type="image" src="images/delete.jpg" height="30" width="30"  name="deleteall" value="delete all" form="delete">
<%@ include file="../design/footer.html" %>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.