I did something very similar to what you have here, but I did a DualServletOutputStream where if the printwriter was requested from the HttpServletResponseWrapper, I would return a new PrintWriter that wrapped my DualServletOutputStream. The dual output stream contains the super.getOutputStream() (the actual response output) and the BufferedOutputStream that is used to getByteArray() and cache it.
It's very strange though because again, HTML files are successfully cached and I can even look at the serialized content on the file system, but 0 bytes are written from JSP requests, even though I can see in my Log4j output that indeed the getWriter() method was called on my HttpServletResponseWrapper. Best Regards, Jacob Hookom -----Original Message----- From: li pan [mailto:[EMAIL PROTECTED]] Sent: Friday, January 24, 2003 11:01 PM To: [EMAIL PROTECTED] Subject: RE: [Tomcat 4.1] Caching JSP Output via Filter PLZ HELP!! Hello Jacob I have successfully implemented this idea. I guess you mean that get the writer of JSP, and replace the writer with another one which will cache the jsp results as well as output them to the original writer? Yes, it works. I didn't use a filter, I simply hacked tomcat, so that my cache facility can be used by any web applications without modifying source codes of them. But I didn't get trouble by getWriter(), I guess maybe : 1 before you get the writer from the filter, tomcat has already done something to the writer? I get it right after the JSP instance is built. 2 tomcat does not allow you to change the writer of a response while it is in the filter chain? I also replace the response with my own wrapper, so I don't change it. Here is my buffered writer: package servercache; import java.io.PrintWriter; import java.nio.CharBuffer; public class BufferedPrintWriter extends PrintWriter { private PrintWriter writer; private CharBuffer buffer = CharBuffer.allocate(1024); public BufferedPrintWriter(PrintWriter writer) { super(writer); //doesnot make any sense. this.writer = writer; } public void write(char[] buf, int offset, int count) { writer.write(buf, offset, count); buffer.put(buf, offset, count); } public void write(String str) { writer.write(str); buffer.put(str); } public void print(String str) { writer.print(str); if (str == null) { buffer.put("null"); } else { buffer.put(str); } } public void println(String str) { writer.println(str); buffer.put(str); buffer.put("\n"); } public CharBuffer getBuffer() { return buffer; } } and here is how it is created: writer = new BufferedPrintWriter(response.getWriter()); _________________________________________________________________ �����������ѽ��н�������ʹ�� MSN Messenger: http://messenger.msn.com/cn -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]> -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
