• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to call servlet from jsp  RSS feed

 
swzka
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

Can any one tell me how to call a servlet from jsp and use it in JSP?

Thanks,

swzka
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can <jsp:include> a servlet, which will put the result of running that servlet into the output.
Is that what you are after?
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Most of the time, the flow is in the other direction: You call the servlet first. It does whatever it needs to do, and then it forwards to the JSP.

If part of the page needs to be generated by a servlet and part by the JSP, you could simply call the servlet in a <jsp:include> tag like this:

<jsp:include page="/myServlet" />

My servlet would get called and whatever HTML output it produces would get included in the page.

If you want to call the servlet based on a user's action at runtime and modify the page without submitting the form, that's a whole different story. For that, you would need to make an AJAX call to the server. It's beyond the scope of this forum to explain how to perform an AJAX call. You'd need to spend some time learning JavaScrpt and AJAX in order do this.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!