-2

I am trying to get a table rows from a JSP page to Servlet but ended up with the following error. What is the correct way of doing it?

Severe:   java.lang.NullPointerException
at com.pg.servlet.session.Controller.doPost(Controller.java:125)

java:

        String[] recordsToUpdate = request.getParameterValues("attTable");

        try {
            for (int i = 0; i < recordsToUpdate.length; i++) {
                total = SQLHelper.Update(recordsToUpdate[2], recordsToUpdate[3], recordsToUpdate[0]);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }

html:

<table id="attTable" class="table">
        <tr class="header">
            <th>Id</th>
            <th>Name</th>
            <th>Present?</th>
            <th>Remarks</th>
        </tr>
        <c:forEach var="List" items="${myVar}" varStatus="iter">
            <tr class="row">
                <td>${List.Id}</td>
                <td>${List.Name}</td>  
                <td><input type="checkbox" name="chkDisperse"></td>
                <td>
                    <input type="text" name="remarks">
                </td>
            </tr>
        </c:forEach>
    </table>
Roman C
  • 49,761
  • 33
  • 66
  • 176
Abdul Gafoor M
  • 107
  • 1
  • 3
  • 9

2 Answers2

1

The request does not contain a parameter by name "attTable" as it is not part of the form input types. This results in the recordsToUpdate being null and hence the NullpointerException when the method length is called on the null object.

Pallavi Sonal
  • 3,661
  • 1
  • 15
  • 19
0

You can add a hidden field with name='Id' in each tr and You have to pass request.getParameterValues("Id") in your servlet. Please check the following stackoverflow question.

Accessing HTML-Input field arrays in Java Servlet / Structure of the input fields

Community
  • 1
  • 1
Silvestor
  • 60
  • 9