Pl. help in handling button events in JSP like calling a servlet on Button click or executing java code.

well u can submit a form from the onclick event on a button element.
with the form action being the file name or serlvet, or u could have a struts action, i would go with the struts action.

Pl. help in handling button events in JSP like calling a servlet on Button click or executing java code.

What to do if more than 1 buttons are there??Plz help in that case..!

Description of the problem in both cases is inaccurate. Please provide better description and supporting examples of coding

I want to execute a particular block of code if button1 is clicked and another set of code if button2 is pressed. Plz help in that case. for example.. Login and Sign up are two buttons on a jsp page.

For that you choose very bad example as I can do it in least two ways and it will have nothing to do with JSP scriplets

  • Each button in its own form where button click will trigger different action
  • Two images of buttons working as links, once you click on one of them you go to different page

Please see the following Code :

HTML FILE

<form action="calculate.jsp">
<input type="Submit" name="Enter" value="see"></input>
<input type="Submit" name="Enter" value="saw"></input>
<input type="Submit" name="Enter" value="seen"></input>

In calculate.jsp

request.getParameter("Enter")

Here it will return the value of Button "Enter" as per the button clicked and you can apply different If ELse loops upon the value of the Enter button

Edited 6 Years Ago by peter_budo: Keep it Organized - For easy readability, always wrap programming code within posts in [code] (code blocks)

This question has already been answered. Start a new discussion instead.