This week's book giveaway is in the OCAJP 8 forum.
We're giving away four copies of OCA Java SE 8 Programmer I Study Guide and have Edward Finegan & Robert Liguori on-line!
See this thread for details.
The moose likes Servlets and the fly likes Including jsp output in a servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of OCA Java SE 8 Programmer I Study Guide this week in the OCAJP 8 forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Including jsp output in a servlet" Watch "Including jsp output in a servlet" New topic

Including jsp output in a servlet

Adam Rose

Joined: Jul 04, 2002
Posts: 5

I was hoping to use a jsp to produce the body content of an email that I am sending from a servlet. From within a servlet, I would like to obtain an InputStream that supplies me with the output of the jps that produces the body content. Is there any way to do this? as far as I can see the ServletContext.getServlet() method has been deprecated and not replaced by anything - how can I communicate with another servlet? I don't want to forward or redirect to it - I actually want to use its output in my repsonse. This seems like it would be a really easy thing to do, but it proving very elusive. I don't really want to generate a whole new request and use this response stream, because I need to be in the same session, and I don't really want the URL to be externally defined. Surely there is a way to get a jsp as an InputStream.... thanks in advance,
Mike Curwen
Ranch Hand

Joined: Feb 20, 2001
Posts: 3695

Have you considered the include(request, response) method of the RequestDispatcher ?
Adam Rose

Joined: Jul 04, 2002
Posts: 5
Hi Mike,
I am trying to use that now, thanks. Once I have called that, do you know how to get the HTML it returned out of the response object? All I seem to be able to get is an OutputStream
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13018
How about creating a derivative of HttpServletResponseWrapper where you sneak in your own OutputStream? I've never tried it but it looks posible from the API.
I agree. Here's the link:
subject: Including jsp output in a servlet
It's not a secret anymore!