Html正文“onload”无法在Chrome中运行

时间:2015-03-12 06:57:58

标签: javascript html google-chrome servlets

我用servlet和jsp编写了示例Web应用程序。根据以下代码,动作URL应自动执行 根据" onload"。我在下面的代码中写了下面的代码,下面是" onload"形式击中了行动路径 仅在Firefox和IE中,但不在Chrome中(41.0.2272.74 beta-m(64位))。我看到链接Chrome - is not working 但我没有得到正确的想法,我的下面的代码在最后的servelt。在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();

上述动作网址中是否有任何保留的关键词?

2 个答案:

答案 0 :(得分:0)

您可以在该html页面的脚本标签中尝试功能。

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

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

答案 1 :(得分:0)

经过一番调查,我终于找到了解决问题的方法。我忘了在servlet中设置响应的Content类型。

response.setContentType(&#34; text / html; charset = UTF-8&#34;);

Chrome浏览器将使用上一行以html页面的形式显示响应。

相关问题