0

I have a html file with 4 buttons. The action for all 4 buttons is the same as shown below:

  <form action="Welcome" method="post">

So that means either of the 4 buttons I click on, it will go to the Welcome servelet, which is currently empty. In the welcome servlet, I need to somehow redirect to other servlets based on what button is clicked. Could somebody please tell me how to do this please, below is my html code, thanks in advance! Much appreciated.

Options.html

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>Options</title>
</head>

<body>
  <form action="Welcome" method="post">
    <h3>
Options
</h3>

    <input type="submit" value="View Personal Information" name="vpi">
    <br>
    <br>
    <input type="submit" value="View Expense Claims" name="vec">
    <br>
    <br>
    <input type="submit" value="View Payslips" name="vps">
    <br>
    <br>
    <input type="submit" value="Change Password" name="cp">
  </form>
</body>

</html>
Programmer
  • 1,266
  • 5
  • 23
  • 44
  • The dupe answers your Y-problem, but your X-problem should be solved by simply using idempotent links. – BalusC Jan 03 '16 at 11:23

2 Answers2

0

You could use multiple radio buttons and only one submit button. If not, you can write a javascript code that listens for the button clicks. When a button is clicked, assign its value to a hidden input that will be submitted with the form request.

Eng.Fouad
  • 115,165
  • 71
  • 313
  • 417
  • I was thinking more on the lines of using an 'if statement' in my welcome.java servlet, like....if(vpi) then go to (insert servlet name) but I'm not sure how to implement this. – Programmer Jan 03 '16 at 12:01
0

Say you have object reference variable named request of type HttpServletRequest, then you simply use request.getParameter(String paramName) this will return the value of the button.

String value = request.getParameter("vpi");

In your example, this will return value as View Personal Information

Mandeep Rajpal
  • 1,667
  • 2
  • 11
  • 16