Retrieving JSP on the server side
Does anyone know how can I retrieve the contents of a JSP on the server side?
Let's say that the user makes a request to a servlet. In that servlet I want to retrieve another JSP (but not include it in the response).
I cannot use servletContext.getResourceAsStream() as this will not process the JSP.
I want to retrieve the JSP contents as a string and process it in the servlet.
An idea will be to use a response wrapper and to override the already defined output stream/writer with my own ByteArrayOutputStream. I tried this already, but it doesn't work.
Does anyone have any other ideas?
Thanks,
Adrian.
[659 byte] By [
beradriana] at [2007-11-27 6:08:36]

# 2
This would be a good idea, but I don't want to handle the cookies and everything to be sure that I have the same session. Moreover I would like to transmit something using the request attributes.
Using an http client library (like the one from Apache) came into my mind in the first place, but as I said, can become pretty messy and I don't have a way to use the request attributes for intercommunication. Practically I would to use the same request object.
If there is any way for doing this taking into account these restrictions would be great.
Thanks,
Adrian.
# 3
To get a response to the Servlet rather than the user, you need to make a request from the servlet, rather than the user. That means making a new request.
The real story is that you have a poorly designed system. Instead of making a JSP that makes display that you don't want, so that you can filter it out in the servlet, redesign the system to meet your requirements.
Such as:
1) Make a servlet which does processing on request attributes/session etc... and provides results of said processing in request attributes
2) Have your JSP call Servlet 1) and create a display out of the returned data
3) Have another Servlet (the one you are working on now) call Servlet 1) to get the same information and work on it without the disply generated by the JSP.
Why have a JSP when you are throwing away what it is good at?