Can JSP flush their output?

Discussion in 'Java' started by ennio, Sep 5, 2006.

  1. ennio

    ennio Guest

    Hi all.
    I'd like to talk about jsp's. I'm working with tomcat 4.1.
    I would like to know if i can somehow "flush" the output stream of my
    jsp as the output is produced.
    In the following tiny (odd) example:
    ---------CUT---------------
    <html>
    <h1> start </h1>
    <%
    Thread.sleep(10000);
    %>
    <h1> end </h1>
    </html>
    ---------CUT---------------
    I would like to see the "start" string before the thread starts
    sleeping.
    Actually i don't : i get it simultaneously with the "end" string.
    Is there a way to easily achieve this in jsp's? Without
    javascript/dhtml/ajax stuff i mean.
     
    ennio, Sep 5, 2006
    #1
    1. Advertising

  2. ennio wrote:
    > I'd like to talk about jsp's. I'm working with tomcat 4.1.
    > I would like to know if i can somehow "flush" the output stream of my
    > jsp as the output is produced.
    > In the following tiny (odd) example:
    > ---------CUT---------------
    > <html>
    > <h1> start </h1>
    > <%
    > Thread.sleep(10000);
    > %>
    > <h1> end </h1>
    > </html>
    > ---------CUT---------------
    > I would like to see the "start" string before the thread starts
    > sleeping.
    > Actually i don't : i get it simultaneously with the "end" string.
    > Is there a way to easily achieve this in jsp's? Without
    > javascript/dhtml/ajax stuff i mean.


    You can try calling out.flush() but I seriously doubt
    you will get it working as you want to.

    I think you should go the AJAX route.

    Arne
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Sep 5, 2006
    #2
    1. Advertising

  3. Arne Vajhøj wrote:
    > ennio wrote:
    >> I'd like to talk about jsp's. I'm working with tomcat 4.1.
    >> I would like to know if i can somehow "flush" the output stream of my
    >> jsp as the output is produced.
    >> In the following tiny (odd) example:
    >> ---------CUT---------------
    >> <html>
    >> <h1> start </h1>
    >> <%
    >> Thread.sleep(10000);
    >> %>
    >> <h1> end </h1>
    >> </html>
    >> ---------CUT---------------
    >> I would like to see the "start" string before the thread starts
    >> sleeping.
    >> Actually i don't : i get it simultaneously with the "end" string.
    >> Is there a way to easily achieve this in jsp's? Without
    >> javascript/dhtml/ajax stuff i mean.

    >
    > You can try calling out.flush() but I seriously doubt
    > you will get it working as you want to.
    >
    > I think you should go the AJAX route.


    And BTW calling Thread.sleep in a JSP page is
    not good !!

    Arne
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Sep 5, 2006
    #3
  4. ennio

    ennio Guest

    Arne Vajhøj ha scritto:
    > You can try calling out.flush() but I seriously doubt
    > you will get it working as you want to.


    I've already tried, it doesn't work
    I was wondering if this thing is possible without involving ajax.
    It's apparently easy: if it's not possible, why is it not?
     
    ennio, Sep 5, 2006
    #4
  5. ennio

    ennio Guest

    > And BTW calling Thread.sleep in a JSP page is
    > not good !!


    it's just an example.
    you can substitute Thread.sleep(10000) with
    doSomethingThatNeeds10SecondsToAccomplish();
     
    ennio, Sep 5, 2006
    #5
  6. ennio

    Oliver Wong Guest

    "ennio" <> wrote in message
    news:...
    > Hi all.
    > I'd like to talk about jsp's. I'm working with tomcat 4.1.
    > I would like to know if i can somehow "flush" the output stream of my
    > jsp as the output is produced.
    > In the following tiny (odd) example:
    > ---------CUT---------------
    > <html>
    > <h1> start </h1>
    > <%
    > Thread.sleep(10000);
    > %>
    > <h1> end </h1>
    > </html>
    > ---------CUT---------------
    > I would like to see the "start" string before the thread starts
    > sleeping.
    > Actually i don't : i get it simultaneously with the "end" string.
    > Is there a way to easily achieve this in jsp's? Without
    > javascript/dhtml/ajax stuff i mean.


    What the client actually sees on their screen is browser dependent. The
    browser may, for example, refuse to render anything until the entire page is
    downloaded, regardless of what you do on the server side.

    - Oliver
     
    Oliver Wong, Sep 5, 2006
    #6
  7. ennio wrote:
    > Arne Vajhøj ha scritto:
    >> You can try calling out.flush() but I seriously doubt
    >> you will get it working as you want to.

    >
    > I've already tried, it doesn't work
    > I was wondering if this thing is possible without involving ajax.
    > It's apparently easy: if it's not possible, why is it not?


    I do not think the servlet specification requires
    the container to actually send the stuff to the
    browser just because you flush it out of the web app.

    [but maybe if you combine it with response.flushBuffer() !]

    I do not think the browser necesarrily will start
    displaying just because it received something.

    If there are a web server in front of the container,
    then it may hold on to things.

    If there are a proxy server in between it may hold
    on to things.

    Arne
     
    =?ISO-8859-1?Q?Arne_Vajh=F8j?=, Sep 5, 2006
    #7
  8. ennio

    ennio Guest

    Arne Vajhøj ha scritto:
    > [but maybe if you combine it with response.flushBuffer() !]


    That's what i was looking for, pal. It does work.
    Thank you very much.
     
    ennio, Sep 6, 2006
    #8
    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. Andrea Desole
    Replies:
    1
    Views:
    2,873
    John C. Bollinger
    Oct 24, 2003
  2. carlisle411
    Replies:
    4
    Views:
    12,326
    John C. Bollinger
    Feb 28, 2005
  3. Fernando Arbeiza

    Will reading from stdin() flush output to stdout()?

    Fernando Arbeiza, Feb 4, 2004, in forum: C Programming
    Replies:
    3
    Views:
    628
    Fernando Arbeiza
    Feb 5, 2004
  4. spidey12345
    Replies:
    2
    Views:
    405
    spidey12345
    Feb 8, 2007
  5. PerlFAQ Server
    Replies:
    0
    Views:
    135
    PerlFAQ Server
    Jan 9, 2011
Loading...

Share This Page