0

Can we call a servlet from a JSP, come back and display the response data we get from the servlet in the same JSP? Is it possible to do that?

Basically, I have a pop up in which the user gives some input. I pass this to the servlet and the servlet gives me an acknowledgement number. I would like to display this acknowledgement number in the same pop up.

In the meantime, during which the servlet gives the response, I can display an hour glass in the pop up. Is this possible?

Someone please help me with an example please.

Joe Mastey
  • 26,809
  • 13
  • 80
  • 104

2 Answers2

1

Option 1
You can submit form in your popup jsp and then forward to the same JSP from servlet.
Option 2
You can use ajax and call servlet and then send response (e.g. JSON) back from servlet and update what you need using javascript, jquery.

Alex
  • 11,451
  • 6
  • 37
  • 52
0

Yes we can call servlet from jsp.

To call servlet from jsp use,

<form action="../Your_servlet_name_in_web.xml_file">

And to call JSP from servlet use,

response.sendRedirect("Your_JSP_NAME.jsp");

For calling servlet from jsp

Hope this will help you.

Rohan
  • 3,068
  • 1
  • 20
  • 26