Return-Path: Delivered-To: apmail-jakarta-tomcat-dev-archive@apache.org Received: (qmail 50531 invoked from network); 23 May 2003 20:23:08 -0000 Received: from exchange.sun.com (192.18.33.10) by daedalus.apache.org with SMTP; 23 May 2003 20:23:08 -0000 Received: (qmail 9836 invoked by uid 97); 23 May 2003 20:25:21 -0000 Delivered-To: qmlist-jakarta-archive-tomcat-dev@nagoya.betaversion.org Received: (qmail 9829 invoked from network); 23 May 2003 20:25:21 -0000 Received: from daedalus.apache.org (HELO apache.org) (208.185.179.12) by nagoya.betaversion.org with SMTP; 23 May 2003 20:25:21 -0000 Received: (qmail 49703 invoked by uid 500); 23 May 2003 20:22:59 -0000 Mailing-List: contact tomcat-dev-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Tomcat Developers List" Reply-To: "Tomcat Developers List" Delivered-To: mailing list tomcat-dev@jakarta.apache.org Received: (qmail 49692 invoked from network); 23 May 2003 20:22:58 -0000 Received: from e250.wspackaging.com (HELO wlcexch01.wspg.com) (209.83.39.92) by daedalus.apache.org with SMTP; 23 May 2003 20:22:58 -0000 Received: from mail1.wspackaging.com ([10.2.1.21]) by wlcexch01.wspg.com with Microsoft SMTPSVC(5.0.2195.5329); Fri, 23 May 2003 15:23:01 -0500 Received: from WLCJOHNCXP (wlcjohncxp.wspg.com [10.2.7.83]) by mail1.wspackaging.com (8.9.3/SCO5) with ESMTP id PAA04443 for ; Fri, 23 May 2003 15:22:38 -0500 (CDT) Reply-To: From: "Chad Johnson" To: "'Tomcat Developers List'" Subject: RE: Calling a generated JSP servlet directly Date: Fri, 23 May 2003 15:23:01 -0500 Organization: WS Packaging Group Message-ID: <003701c32169$1b9afa50$5307020a@wspg.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook, Build 10.0.4024 In-Reply-To: <61BAD406AA642745AE1142AF689E8D8E030ADF@madocontrol.madocke.local> X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1106 Importance: Normal X-OriginalArrivalTime: 23 May 2003 20:23:01.0466 (UTC) FILETIME=[1B96DBA0:01C32169] X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N Hey, I do understand what your saying (I do this myself). Here's the approach I took. 1.) From a servlet do a Request Dispatch Forward [RequestDispatcher.forward(ServletRequest request, ServletResponse response)] 2.) Notice you feed the Forward a ServletResponse. Implement your own ServletResponse that stores all the output in a String. I have a class attached below. Note this is a rather weak implementation of ServletResponse. But it gets the job done for me. Usage would be something like: StringHttpServletResponse stringResponse = new StringHttpServletResponse(); RequestDispatch.forward(request,stringResponse); String output = stringResponse.toString(); -Chad Johnson =================================== import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class StringHttpServletResponse implements HttpServletResponse { private StringWriter dataString; public StringHttpServletResponse() { this.dataString = new StringWriter(); } public PrintWriter getWriter() throws IOException { return new PrintWriter(dataString); } public ServletOutputStream getOutputStream() throws IOException { return new ServletOutputStream() { public void write(int i) { byte b[] = new byte[1]; b[0] = (byte)i; dataString.write(new String(b)); } }; } public String toString() { return dataString.toString(); } public String getCharacterEncoding() { return "ISO-8859-1"; } public int getBufferSize() { return 512; } public boolean isCommitted() { return false; } public Locale getLocale() { return Locale.US; } public boolean containsHeader(String arg0) { return false; } public String encodeURL(String arg0) { return arg0; } public String encodeRedirectURL(String arg0) { return arg0; } public String encodeUrl(String arg0) { return arg0; } public String encodeRedirectUrl(String arg0) { return arg0; } public void addCookie(Cookie arg0) {} public void sendError(int arg0, String arg1) throws IOException {} public void sendError(int arg0) throws IOException {} public void sendRedirect(String arg0) throws IOException {} public void setDateHeader(String arg0, long arg1) {} public void addDateHeader(String arg0, long arg1) {} public void setHeader(String arg0, String arg1) {} public void addHeader(String arg0, String arg1) {} public void setIntHeader(String arg0, int arg1) {} public void addIntHeader(String arg0, int arg1) {} public void setStatus(int arg0) {} public void setStatus(int arg0, String arg1) {} public void setContentLength(int arg0) {} public void setContentType(String arg0) {} public void setBufferSize(int arg0) {} public void flushBuffer() throws IOException {} public void resetBuffer() {} public void reset() {} public void setLocale(Locale arg0) {} } --------------------------------------------------------------------- To unsubscribe, e-mail: tomcat-dev-unsubscribe@jakarta.apache.org For additional commands, e-mail: tomcat-dev-help@jakarta.apache.org