-1

How can I fetch the value of name(which is either 1 or 2) in the forms below, in the RegisterRedirect servlet?

....

<tr>
        <td><form action="RegisterRedirect" method="post">
            <input type="submit" name="1" value="Edit"></form></td>
        <td><form action="RegisterRedirect" method="post">
            <input type="submit" name="2" value="Delete"></form></td>
</tr>

.....
user1232138
  • 5,451
  • 8
  • 37
  • 64

1 Answers1

0

You can get all the names first. Since you only have one element, get the next one. So in your doPost method from RegisterRedirect:

Enumeration<String> names = request.getParameterNames();
String firstAndOnlyElem = names.nextElement();
System.out.println(firstAndOnlyElem);
System.out.println(request.getParameter(firstAndOnlyElem));

You will get the 1 and Edit clicking on the submit button from the first form.

rhenesys
  • 174
  • 1
  • 11