Skip to content
Advertisement

How can I call servlet from jsp without using form

This could be a repeat question, I apologize. I have a jsp page in which I have some buttons. Each button has its own servlet to call. I want to know if there is any way I can call these servlets without using form because the user may choose any of the 3 functionalities given. I also need to pass a value from the jsp page to the servlets I call.

JavaScript

Advertisement

Answer

I see 2 options here:

  1. Changing a form’s URL accordingly to each button using JavaScript, right before sendiing a POST request;

  2. Use a form and the same servlet for all 3 cases. In the servlet you should determine what button has been pressed (their values are passed as a request parameter) and then go forward accordingly.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement