auto refresh of jsp page


Web tier: servlets, JSP, Web frameworks: auto refresh of jsp page

  1. auto refresh of jsp page (4 messages)

    I have a counter field on the jsp page where it needs to be refreshed automatically for every 1 minute without refreshing the entire home page. I am using Timer class to get new values from Oracle database for every 30 seconds. I am able to get these updated value from database and display on jsp page but its refreshing the entire home page. It has to refresh only the counter field. I'm using meta tag on jsp page to get udpated value. How can i get the dynamic value into jsp page without refresh. This is urgent. can you please help.
  2. Hi Bujji,

    One can have many ways of solving this problem but here I will suggest a simplest one.

    1. Create a hidden frame in the home page.
    (Hidden frame is the one which has width = 0).

    2. Create s small refresh.jsp with similiar automatic refresh attribute set so that at fixed interval it will make a request to server.

    3. In its response it will bring the new value from server.

    4. On loading this response page, execute a javascript function which will get the reference to field and updates its value.

    I assure you that this will work well. So go ahead. Good luck.

    Is this a best solution ?
    Not really. If you can dig-in further you can use XML.HTTP2 activex control for making a behind-the-screen call to server. This solution is very similiar to any AJAX based solution but you will have to work on it.

    In my opinion, if you are tight on timeline follow first suggestion.

    Hope this helps.

    Good luck.
  3. See for example Ajax div taglib in Coldtags suite:
  4. auto refresh of jsp page[ Go to top ]

    You can use the following JS function. All you have to do is write a Servlet that writes the Counter value to the response.
    Pass the Servlet url to this function and fill it in a DIV or an Input field.

    function readContent(urltoRead){
    var counter = "";
    try {
    var xmlHttp = null;
    try {
    xmlHttp = new ActiveXObject( "Msxml2.XMLHTTP" );
    } catch (e) {
    xmlHttp = new ActiveXObject( "Microsoft.XMLHTTP" );
    } "GET", urltoRead, false );
    // Execute the request
    if(xmlHttp.status == 200)
    counter = xmlHttp.ResponseText;
    counter = "Unknown";
    } catch(errmsg) {
    counter = "Unknown Counter";
  5. auto refresh of JSP Page[ Go to top ]

    I am displaying no. of records in one frame. now whenever i am inserting a new record, my display page in not getting auto refreshed. i want to refresh only that frame in which my display page is showned. Can you help me out with some code of it. my e-mail is shahdhruv at cooltoad dot com Thanks... Dhruv Shah