Html Servlet 中的表单将命中浏览器

Html Form in the Servlet will hit the browser

我的应用程序中有 2 个 servlet,我将从第一个 servlet 调用第二个 servlet,如下所示:

public FirstServlet extends HttpServlet {

  public void doPost(HttpServletRequest request, HttpServletResponse resp) {
     out.write("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"> \n");
        out.write("<html><head><body onload=\"document.forms[0].submit()\">\n");
        out.write("<form method=\"POST\" action="/Demoproject/secondServlet">\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");

}

}

所以根据上面的 html 形式,流程转到在 web.xml.

中配置的第二个 servlet

我的问题是:

Is the html form in FirstServlet.java will go to the browser?

是的,它将首先转到浏览器

因为 document.forms[0].submit() 是一个 javascript 函数,而 html 你写的是客户端语言,只会在浏览器中执行。

FirstServlet--->Browser---applies the javascripst submit by checking form code--->SecondServlet