GeeCON Prague 2014*
The moose likes Servlets and the fly likes printwriter Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "printwriter" Watch "printwriter" New topic
Author

printwriter

Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
sorry i posted this in multiple forums but this just drives me crazy right now. I can't figure out why i can't get an output. Sorry again for post many times. here is the query.
hi i have this method in my code that i wrote to send a message to clients. Now if i change the code to use PrintWriter it says that print writer with every println() method is flushing the buffer it doesn't WORK . i tried everything nothing happends. Now i try to use BufferedWriter same story. I use flush method to flush it nothing happends. I used to specify a buffer size trying to limit it to the length of the string and then flush it again nothing happends. What do i do wrong ? Code is below. The only way it flushes is only when the buffer get's overloaded.


Val SCJP <BR>going for SCJD
vaibhav punekar
Ranch Hand

Joined: Jan 20, 2001
Posts: 134
Hi,
If this is the code in your servlet,then try passing the PrintWriter out as parameter toy uor method.If it is a standalone class I think you will have to import Servlet pacage and use the PrinWriter object as parameter to your method.


VAIBHAV <BR>SCJP
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
THis is a standalonne class which i start it by command line. Servlets access it and it sends back the data to them well it should. But it doesn't flush it when data arrives.
Val Dra
Ranch Hand

Joined: Jan 26, 2001
Posts: 439
well it drove me nuts but i got it solved. Not that it was something hard to do but just overlooked HttpServletResponse object which has bufferFlush method. When dealing with more then one Stream it gets tied. I tried to flush on my stream that i get from one of the Server classes which ofcouse didnt' do anything instead must have used HttpServletResponse object. So i post this message just incase someone runs into this.
Thanks and bye
 
GeeCON Prague 2014
 
subject: printwriter