Peter Delahunty wrote:
>
> Situation:
>
> I want to have a servlet that in servlet engine is mapped to run when ever
> any request comes in for any other servlet in my system. I then want this
> front servlet(A) to call the intended servlet(B) and read the output of (B)
> into a string. I will then use this string else where but this is
> irrelevant. Once i have this string i then want to return the response
> (which will be the string) to the user.
>
> So how do i do this eloquently. The way i see it the servlet api has
> migrated to make this very hard to achieve in a neat way.

Create your own class that contains a reference of type HttpServletResponse as a
member; your class implements the HttpServletResponse interface, call it
MyHttpServletResponse.

Servlet A gets called with a request. Servlet A instantiates
MyHttpServletResponse, passing it a reference to the HttpServletResponse. The
reference is saved by the MyHttpServletResponse class. The request is dispatched
to servlet B.

MyHttpServletResponse delegates all method calls to HttpServletResponse except
the getOutputStream and getWriter call. MyHttpServletResponse implements
getOutputStream by returning a reference to a new ByteArrayOutputStream wrapped
in a BufferedOutputStream; the getWriter returns a StringWriter wrapped in a
BufferedWriter.

MyHttpServletResponse also defines a getString method. When the request dispatch
call returns to Servlet A, servlet A can call the getString method.
MyHttpServletResponse returns the String that was written to the
ByteArrayOutputStream or the StringWriter by Servlet B.

K Mukhar

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to