1

I have a HTML page. On the page I have a link. When the user click on the link, I am calling a servlet which opens in a new page. On this servlet, I'm trying to update my database. After completing the update, I'm able to close the page launched from the servlet. Now I want to run a script on the original HTML page, but am unable to do so, since there is no trigger/event to call that method.

How do I do this. Thanks in advance!

  • Well, your servlet doesn't "open a new page", it performs an operation and ends by displaying a page or redirecting to another page. Please clarify. – Andreas Aug 18 '15 at 20:54
  • when the user hits the link, he is directed to a new URL(which opens in a new browser window and is out of my control) which is a call to the servlet eg: demo.html is my current html page. When user hits the link a new new window will open with url: ? –  Aug 18 '15 at 21:04
  • try to redirect user using url provided by `request.getHeader("Referer")` – itwasntme Aug 18 '15 at 21:15

1 Answers1

1

You could use ajax to poll the status of your backend process executed by the servlet. When it is finished, you execute whatever you want. Something like:

var checkStatusTimeout;

function checkStatus(){
    $.ajax({
        type: "GET",
        url: "./getstatus",
        dataType: "text",
        contentType: "application/json; charset=utf-8",
        success: function(status){
            if (status == 'FINISHED'){
                clearTimeout(checkStatusTimeout);
                // execute whatever you want here
            }
        }
    });

    checkStatusTimeout = window.setTimeout("checkStatus()", 5000);
}

You should call the function checkStatus() when the user clicks on the link.

Or you could assign the child window used by the servlet to a variable and check it from time to time to verify if the window was closed. Check the answer from Mark Coleman on javascript: How Can a parent window know that its child window closed? for instructions.

Community
  • 1
  • 1
  • Let me add some more details to my question. The link is actually in a tooltip from a view I have embedded from tableau online. Whenever I click the link,a call to "tableau server" is made, which then redirects me to a new page(I can control the link to this page) which opens in a new tab. I'm calling the servlet from this link. In the servlet I'm able to modify my database. Now I want to go back to the previous page and then update the view. I can update the view using JS but for that I need to run a script on the original page. –  Aug 18 '15 at 21:53
  • If I understood your problem correctly, when clicking on the link a new tab is opened and when the servlet finishes this tab is closed. Is that right? If so, you could use the answer from Mark Coleman and run a script on the page 1 to check when page 2 (the servlet tab) is closed. When that happens, you can update the view. Will that do the trick or did I miss something? – Gustavo Zago Basilio Aug 18 '15 at 22:14