Just give the buttons a name and value as with every other HTML input element. Only the name=value
pair of the actually pressed button will be sent to the server as request parameter. You can then determine the action based on the value:
<input type="submit" name="action" value="edit">
<input type="submit" name="action" value="delete">
..with the following in the Servlet:
String action = request.getParameter("action");
if ("edit".equals(action)) {
// Edit button was pressed.
} else if ("delete".equals(action)) {
// Delete button was pressed.
}
You can also give the buttons a different name so that you just need to check its presence in the request parameter map:
<input type="submit" name="edit" value="edit">
<input type="submit" name="delete" value="delete">
..with the following in the Servlet:
String edit = request.getParameter("edit");
String delete = request.getParameter("delete");
if (edit != null) {
// Edit button was pressed.
} else if (delete != null) {
// Delete button was pressed.
}
No need for Javascript hacks/workarounds. It would only make your website unuseable when the client has JS disabled.