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.

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

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

how to create a button in jsp ?
and calling function in java after from this button

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.