Client side waiting & timeout

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Simon_21

    Client side waiting & timeout

    Hi All,

    I have a servlet which is invoked from a jsp page. While the serlvet
    is executing, the jsp page is waiting for the servlet to complete.
    When the servlet completes, it informs the waiting jsp to redirect to
    another page. The waiting jsp has implemented onload which will
    redirect to the page informed by the servlet


    Server : (tomcat 6.0), Browser - IE 6.0, OS - WinXP



    When the servlet takes a long time to return, the page is not
    redirected. It seems the browser has given up on the request or timed
    out . If the servlet comes back quickly, it works fine. The problem is
    seen when the servlet takes a long time to finish.



    //waiting jsp code

    <html>
    <head>
    <title>Please wait......</title>

    </head>

    <body style='width: 100%;' onload='dynamic Redirect();'>

    <br><br>
    <div class='indent'> <div id='dynamicDisp lay'</div></div>
    <script>dynamic DisplayScript( 0, 'please wait' );</script<br><br>



    <%
    out.flush();

    //wait for the serlvet to finish
    String servlet_url = "/servlet/ComputeServlet" ;
    request.getRequ estDispatcher( servlet_url ).include( request,
    response );

    %>



    <SCRIPT language='JAVAS CRIPT'>

    function dynamicDisplayS cript( x, info )
    {
    var y = 0;
    var tab = FindElementById ( "dynamicDisplay " ) ;
    var display_val = "<h2>"+info ;
    var display_end = "</h2>";

    if( Number( x ) == 0 )
    {
    tab.innerHTML = display_val+ "." +display_end;
    y = 1;
    }
    else if( Number( x ) == 1 )
    {
    tab.innerHTML = display_val+ ".." +display_end;
    y = 2;
    }
    else if( Number( x ) == 2 )
    {
    tab.innerHTML = display_val+ "..." +display_end;
    y = 3;
    }
    else if( Number( x ) == 3 )
    {
    tab.innerHTML = display_val+ "...." +display_end;
    y = 4;
    }
    else if( Number( x ) == 4 )
    {
    tab.innerHTML = display_val+ "....." +display_end;
    y = 0;
    }

    var wait = 1000;
    window.setTimeo ut( "dynamicDisplay Script(" + y + ", '" + info
    + "' )", wait );
    }


    //This is called after the page is loaded when the servet returns
    function dynamicRedirect ()
    {
    <%
    String url = ( String )request.getAtt ribute( "RedirectUR L");

    %>
    window.location = url;
    }

    </SCRIPT>

    Appreciate any help

    Thanks

    _Pete
  • Thomas 'PointedEars' Lahn

    #2
    Re: Client side waiting &amp; timeout

    Simon_21 wrote:
    I have a servlet which is invoked from a jsp page. While the serlvet
    is executing, the jsp page is waiting for the servlet to complete.
    When the servlet completes, it informs the waiting jsp to redirect to
    another page. The waiting jsp has implemented onload which will
    redirect to the page informed by the servlet
    >
    Server : (tomcat 6.0), Browser - IE 6.0, OS - WinXP
    >
    When the servlet takes a long time to return, the page is not
    redirected. It seems the browser has given up on the request or timed
    out . If the servlet comes back quickly, it works fine. The problem is
    seen when the servlet takes a long time to finish.
    >
    //waiting jsp code
    Almost irrelevant.
    var tab = FindElementById ( "dynamicDisplay " ) ;
    Where is FindElementById () defined, and why does it have an identifier that
    suggests a constructor or a factory?
    if( Number( x ) == 0 )
    This is pointless. Unlike Java, ECMAScript implementations implement `=='
    as a type-converting comparison that implicitly does more efficiently what
    you write explicitly here.
    else if( Number( x ) == 1 )
    [aso.]
    Very inefficient and hard to maintain. Consider this instead:

    if (x >= 0 && x <= 4)
    {
    tab.innerHTML = display_val+ "...." +display_end;
    y = (x + 1) % 5;
    }
    window.setTimeo ut( "dynamicDisplay Script(" + y + ", '" + info
    + "' )", wait );
    You might want to use the well-supported (JavaScript 1.2+, NN 3+, IE 5+)

    window.setTimeo ut(
    function() {
    dynamicDisplayS cript(y, info);
    },
    wait);

    instead. However you do it, don't forget to store your timeout and clear it
    onunload.
    <% String url = ( String )request.getAtt ribute( "RedirectUR L"); %>
    Isn't that even pointless in Java? I suppose request.getAttr ibute() already
    returns a reference to a String object -- why the typecast?
    window.location = url;
    This is not going to work, of course. The client-side script does not know
    about the server-side `url' variable. You will need to do something like

    <%= "window.locatio n = '" + request.getAttr ibute("Redirect URL"); + "';" %>

    i.e. the server-side script generating client-side code. Don't forget to
    properly escape the variable value or your client-side string literal might
    break.
    [...]
    Appreciate any help
    Redirect server-side instead.

    BTW, your generated markup is not Valid. See http://validator.w3.org/


    PointedEars
    --
    realism: HTML 4.01 Strict
    evangelism: XHTML 1.0 Strict
    madness: XHTML 1.1 as application/xhtml+xml
    -- Bjoern Hoehrmann

    Comment

    Working...