Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/api/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如何在单击html表单的不同按钮时调用不同的servlet_Javascript_Html_Servlets - Fatal编程技术网

Javascript 如何在单击html表单的不同按钮时调用不同的servlet

Javascript 如何在单击html表单的不同按钮时调用不同的servlet,javascript,html,servlets,Javascript,Html,Servlets,我有一个html表单,我想在单击两个不同的按钮时调用两个不同的servlet如何更改表单操作运行时 <form> <input type="submit" value="Question Paper" style="height:25px; width:120px; background-color: royalblue;color: white;" /> <input type="submit" value="Instruction" style="height:

我有一个html表单,我想在单击两个不同的按钮时调用两个不同的servlet如何更改表单操作运行时

<form>
<input type="submit" value="Question Paper" style="height:25px; width:120px; background-color: royalblue;color: white;" />
<input type="submit" value="Instruction" style="height:25px; width:120px; background-color: royalblue;color: white;" />");
 </form>

");
单击按钮后,我想在每个按钮上调用servlet1和servlet2


请帮我解决这个问题,提前谢谢

有几种方法可以实现这一点

可能最简单的方法是使用JavaScript更改表单的操作

<input type="submit" value="SecondServlet" onclick="form.action='SecondServlet';">
<form action="FirstServlet" method="Post">
    Last Name: <input type="text" name="lastName" size="20">
    <br><br>
    <input type="submit" value="FirstServlet">
</form>
<form action="SecondServlet" method="Post">
    <input type="submit"value="SecondServlet">
</form>
<form action="MainServlet" method="Post">
    Last Name: <input type="text" name="lastName" size="20">
    <br><br>
    <input type="submit" name="action" value="FirstServlet">
    <input type="submit" name="action" value="SecondServlet">
</form>
String action = request.getParameter("action");

if ("FirstServlet".equals(action)) {
    // Invoke FirstServlet's job here.
} else if ("SecondServlet".equals(action)) {
    // Invoke SecondServlet's job here.
}