p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   Servlets (http://p2p.wrox.com/forumdisplay.php?f=111)
-   -   Storing and reusing PrintWriter (http://p2p.wrox.com/showthread.php?t=7304)

delboypass December 16th, 2003 09:31 AM

Storing and reusing PrintWriter
 
I need to know how to store and reuse a printwriter.
Im trying to build a servlet that is able to PUSH javascript commands back to a designated users browser.
To try and do this, i have saved the users printwriter in hashtable.
When the correct event is sent, the users PrintWriter is retrieved from the Hashtable and the browser is written to.

But this doesnt seem to work.
Does anybody know why or how to get around this?
Any help is appreciated.
The printwriter seems to be of type:
Coyotewriter.
{derrick=org.apache.coyote.tomcat5.CoyoteWriter@24 bfaa}

If i use the flush on this printwriter it seems to generate this error

System.out.println("Is this even working: Receivedevent!!!!!!! "+useroutputstream);
PrintWriter usersout = (PrintWriter)useroutputstream.get("derrick");
usersout.println("Testing received event status"+receivedevent);
usersout.print("<script type=\"text/javascript\">");
usersout.print("receivedEvent('your dinner is ready');");
usersout.print("</script>");
//extraline
usersout.flush(); -----> Exception: lbp.LBPServlet.doGet(LBPServlet.java:98)

I dont know if this is also part of the problem but if i use the .flush(), it seems to start throwing exceptions.

java.lang.NullPointerException
org.apache.coyote.http11.InternalOutputBuffer.comm it(InternalOutputBuffer.java:547)
org.apache.coyote.http11.Http11Processor.action(Ht tp11Processor.java:735)
org.apache.coyote.Response.action(Response.java:22 3)
org.apache.coyote.http11.InternalOutputBuffer.doWr ite(InternalOutputBuffer.java:518)
org.apache.coyote.Response.doWrite(Response.java:5 32)
org.apache.coyote.tomcat5.OutputBuffer.realWriteBy tes(OutputBuffer.java:392)
org.apache.tomcat.util.buf.ByteChunk.flushBuffer(B yteChunk.java:439)
org.apache.coyote.tomcat5.OutputBuffer.flush(Outpu tBuffer.java:350)
org.apache.coyote.tomcat5.CoyoteWriter.flush(Coyot eWriter.java:119)
lbp.LBPServlet.doGet(LBPServlet.java:98)
javax.servlet.http.HttpServlet.service(HttpServlet .java:743)
javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
org.apache.catalina.servlets.InvokerServlet.serveR equest(InvokerServlet.java:466)
org.apache.catalina.servlets.InvokerServlet.doGet( InvokerServlet.java:180)
javax.servlet.http.HttpServlet.service(HttpServlet .java:743)
javax.servlet.http.HttpServlet.service(HttpServlet .java:856)
filters.ExampleFilter.doFilter(ExampleFilter.java: 149)
filters.ExampleFilter.doFilter(ExampleFilter.java: 149)







All times are GMT -4. The time now is 08:55 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.