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]>

Reply via email to