• Post Reply Bookmark Topic Watch Topic
  • New Topic

Html body “onload” is not working in Chrome

 
majji naidu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 - <body onload=“”> is not working ][1] 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\" \"http://www.w3.org/TR/html4/loose.dtd\"> \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?

If i execute this code in the html format, it is working in chrome. but if it is from servlet, alert() is not running.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65522
105
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you are using JSP in your project, why are you emitting HTML from the servlet? That's the role of JSP.

Debugging tip #1: do a View Source at the browser to see what it received. Is it what you expect?
 
majji naidu
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The problem with the code is:

We have to set content type before sending response in a servlet:

response.setContentType("text/html");
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!