servlets: flushBuffer does not close the connection

Discussion in 'Java' started by Andy Fish, Nov 17, 2003.

  1. Andy Fish

    Andy Fish Guest

    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
     
    Andy Fish, Nov 17, 2003
    #1
    1. Advertising

  2. "Andy Fish" <> wrote in message
    news:Gp1ub.2244$S%...
    > 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
     
    Dobromir Gaydarov, Nov 18, 2003
    #2
    1. Advertising

  3. Andy Fish

    Andy Fish Guest

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

    I'll forget the whole thing then, thanks.

    "Dobromir Gaydarov" <-THIS.com> wrote in message
    news:...
    > "Andy Fish" <> wrote in message
    > news:Gp1ub.2244$S%...
    > > 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
    >
    >
     
    Andy Fish, Nov 18, 2003
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Paul van Rossem
    Replies:
    0
    Views:
    607
    Paul van Rossem
    Apr 7, 2005
  2. S_K
    Replies:
    6
    Views:
    679
    Russell
    Dec 7, 2007
  3. Dani
    Replies:
    3
    Views:
    487
  4. Iñaki Baz Castillo
    Replies:
    7
    Views:
    873
    Iñaki Baz Castillo
    Jan 12, 2010
  5. hyejin
    Replies:
    8
    Views:
    346
    Martin Honnen
    Aug 29, 2006
Loading...

Share This Page