servlets: flushBuffer does not close the connection

A

Andy Fish

Hi

I have noticed that in a servlet if I do a response.flushBuffer() without
writing any content, the connection to the browser is not closed (tomcat 4
point something).

I would have thought that it is good practice to put a flushBuffer() in at
the bottom of the doGet method so that it gets called whenever there has
been no exception. I can't see anything in the spec to say flushBuffer
should only be called if you have written to the buffer.

Am I doing something stupid here? Or must I really put a flag in my code to
record whether I have written any output?

Andy
 
D

Dobromir Gaydarov

Andy Fish said:
Hi

I have noticed that in a servlet if I do a response.flushBuffer() without
writing any content, the connection to the browser is not closed (tomcat 4
point something).

I do not see why you expect flushBuffer to close the connection.
I would have thought that it is good practice to put a flushBuffer() in at
the bottom of the doGet method so that it gets called whenever there has
been no exception. I can't see anything in the spec to say flushBuffer
should only be called if you have written to the buffer.

Exactly the oposite - there is no point of doing it at the end of doGet.
When the doGet returns everything will happen as it is supposed to and you
do not have to do anything about it.
Am I doing something stupid here? Or must I really put a flag in my code to
record whether I have written any output?

Well, just forget about the method for now. It is for a very specific cases
and you will probably never deal with them.

Regards,
Dobromir
 
A

Andy Fish

OK, I thought I was supposed to do it after writing any output

I'll forget the whole thing then, thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,013
Latest member
KatriceSwa

Latest Threads

Top