Html Body "Onload" Is Not Working in Chrome

I have written sample web application with servlets and jsp. As per the below code the action url should be executed automatically according to the "onload". I have written this below code in one of my servlet, The below "onload" form hits the path in action only in Firefox and IE but not in Chrome(41.0.2272.74 beta-m (64-bit)).I have seen the link Chrome - is not working but i did not get proper idea, I have my below code in the end of servelt. there is nothing to execute after this code in the servlet.

 out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \""> \n");
    out.write("<html><body onload=\"alert('alert has been fired');document.forms[0].submit()\">\n");
    out.write("<form method=\"POST\" action=\"" + actionUrl + "\">\n");
    out.write("<input type=\"hidden\" name=\"resourcePath\" value=\"" + callbackUrl + "\"/>\n");
    out.write("<input type=\"hidden\" name=\"locale\" value=\"" + locale + "\"/>\n");
    out.write("<input type=\"hidden\" name=\"rspjRequest\" value=\"" + true + "\"/>\n");
    out.write("</form>\n</body>\n</html>\n");
    out.close();

Is there any reserved key words of chrome in the above action url?

9

2 Answers

After some investigation finally i got solution for my problem. I forgot to set the Content type for the response in the servlet.

response.setContentType("text/html; charset=UTF-8");

Chrome browser will display response in the form of html page by using above line.

You can try function in script tag of that html page.

  <script>
     function myfunction() {
     alert("This is the first.");
    }

    window.onload = function()
    {
     myfunction;
    }
  </script>
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest