0

I have java web application in which there is a jsp form which has the information fetched from the database.database is changing from time to time ,because there are multiple users for this application, they might be changing the data inside the tables. So am trying to refresh the form after sometime so that my form remain sync with the database,code for refreshing the jsp form is :

var varReloadNewOrders=setInterval(function(){reloadAddedTerminals()},5000);


function reloadAddedTerminals()
    {
        var xmlhttp;
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("suggest").innerHTML=xmlhttp.responseText;

            //  document.getElementById("newOrders").innerHTML=xmlhttp.responseText;
               }
          }

        xmlhttp.open("GET","suggestions/terminalSuggestions.jsp?q=",false);

        //xmlhttp.open("GET","suggestions/getNewOrders.jsp?q=new",true);
        xmlhttp.send();

    } 

The jsp is here:

<% 
UpdateConst constant = new UpdateConst();
TerminalController suggestTerm = new TerminalController();

String value = (String)request.getParameter("q");
System.out.println("terminal suggestion called with value" + value);%>

<table class="documentation">
<thead>
    <tr><th>Serial No</th><th>Terminal ID</th><th>MID</th><th>MID Status</th><th>Edit</tr>
</thead>
<tbody>
<% 
int count = 1;
for(Terminal var : suggestTerm.suggestTerminals(value))
{
%>

    <tr><th><%=count++ %></th><td><%=var.getTID() %></td><td><%=var.getMID() %></td><td><%=var.getMIDSTATUS() %></td><td>
    <a href="<%=constant.getTerminal() + "?id=" + var.getID() +"&tid=" + var.getTID() +"&mid=" + var.getMID()+"&midStatus=" + var.getMIDSTATUS() +"&application=" + var.getApplication() 
    +"&lastTxnDate=" + var.getLastTxnDate()+  "&merchName=" + var.getMerchantName() 
    + "&groupname=" + var.getGroup()+ "&rm=" + var.RM+ "&location=" + var.getLocation()+"&area=" + var.getArea()+"&city=" + var.getCity()+"&posSerial=" + var.getPOSSerialNo()
    +"&posType=" + var.getPOSType()+"&terminalType=" + var.getTerminalType()+"&posAppVer=" + var.getPOSAppVersion()+"&simNumber=" + var.getSIMNumber()
    +"&simType=" + var.getSIMType()  +"&freeparam1=" + var.getFreeParam1()  +"&freeparam2=" + var.getFreeParam2()
    +"&freeparam3=" + var.getFreeParam3()  +"&callType=" + var.getCallType()
    +"&image=" + var.getMerchantName() +"#editcategory"%>">Edit</a></td>

    </tr>
<% 
    }
%>


    </tbody>
    </table>

The page is refreshing properly and getting the updated values from the db but the problem is that if any other tab from the list of tab is open ,at the time of form refresh this form gets to the front. I want it to only refresh when only the tab which has this jsp form is open. please help.

Talib
  • 1,134
  • 5
  • 31
  • 58

1 Answers1

0

You can try

response.setIntHeader("Refresh", 10);

This will refresh your page after every 10 seconds and if other tabs are opened then also it will refresh but will not come in front.

Shubham Pendharkar
  • 310
  • 1
  • 4
  • 17