Win a copy of React Cookbook: Recipes for Mastering the React Framework this week in the HTML Pages with CSS and JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Rob Spoor
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Tim Holloway
  • Piet Souris
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Frits Walraven
  • Himai Minh

How to call servlet from jsp

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Bartender
Posts: 1845
10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Seriously Rick? Seriously? You might as well just read this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic