This week's giveaway is in the Java/Jakarta EE forum.
We're giving away four copies of Java EE 8 High Performance and have Romain Manni-Bucau on-line!
See <script language="JavaScript">
function sendToServlet(buttonPressed) {
if (buttonPressed == 1) {
window.location = "servlet/Add";
}else if (buttonPressed == 2) {
window.location = "servlet/Delete";
}else if (buttonPressed == 3) {
window.location = "servlet/Update";
In your servlet you will have:
out.println("<input type=\"button\" name=\"add\" Value=\"Add\" onClick=\"sendToServlet(1)\">");
Let me know if this works.
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Another way that i will do is to associate a hidden field with each form element. Then set the action of the form to the same servlet and check which hidden values is passed.For example

<Form method="post" action="yourservlet_paht">
<Input type="submit" value="Add">
<Input type="hidden" name="action" value="Add">
<Form method="post" action="yourservlet_paht">
<Input type="submit" value="Modify">
<Input type="hidden" name="action" value="modify">
<Form method="post" action="yourservlet_paht">
<Input type="submit" value="Delete">
<Input type="hidden" name="action" value="delete">
In servlet use request.getParameter("action"), then use .equals() method to check the string value to determine which action to employ. Hope this help.
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!