नमस्ते

While working on Net-Centric Project I came across an obstacle of creating multiple buttons and calling different servlets within the same form. This was in the login page, where we can either login or register by making use of the same form fields ‘username’ and ‘password’.

To do so you can create a button as following:

<input type="submit" id="reg" value="Register" onclick="form.action='registerServlet';">

This would call another Servlet when this button is clicked.

The form will look something like this:

<form method="post" action="loginServlet">
  <input type="text" name="username" value="Username" autofocus >
  <input type="password" name="password" value="Password" >
  <input id="login" type="submit" value="Login" >
  <input type="submit" id="reg" value="Register" onclick="form.action='registerServlet';">
</form>

Happy coding.

Let the Windows be open, and feel the Freedom.

Leave a comment