0

I'm trying to pass data from a jsp page to a servlet to process it.

here is the jsp

<c:forEach var="student" items="${requestScope.resultArray}">
        <c:set var="id" value="${student.id}"></c:set>
        <tr>
            <td><c:out value="${student.id}"></c:out>
            <td><c:out value="${student.firstName}"></c:out></td>
            <td><c:out value="${student.lastName}"></c:out></td>
            <td><c:out value="${student.age}"></c:out></td>
            <td><c:out value="${student.mark}"></c:out></td>
            <td><c:out value="${student.gender}"></c:out></td>
            <td><form action="Update" method="post">
                    <input type="hidden" value="${student.id}" name="stdId"> <input
                        type="submit" value="Edit" name="edit"> <input
                        type="submit" value="Delete" name="delete">
                </form></td>
        </tr>


    </c:forEach>

And here is the servlet

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // TODO Auto-generated method stub

    String string = (String) request.getAttribute("stdId");
    System.out.println(string);
}

The problem is that I'm getting stdId passed as null to the servlet. What is the problem?

doubleH90
  • 163
  • 4
  • 17

1 Answers1

1

Use request.getParameter("stdId"); instead of request.getAttribute("stdId");

Rahul Yadav
  • 1,503
  • 8
  • 11
  • Thanks man, you clicked it on my mind to figure out what are the differences between attributes and parameters. – doubleH90 Sep 07 '15 at 12:25