Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/311.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/453.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
Java 如何从同一个JSP文件向多个servlet发送请求?_Java_Javascript_Jquery_Jsp_Servlets - Fatal编程技术网

Java 如何从同一个JSP文件向多个servlet发送请求?

Java 如何从同一个JSP文件向多个servlet发送请求?,java,javascript,jquery,jsp,servlets,Java,Javascript,Jquery,Jsp,Servlets,我想从同一个JSP导航到多个servlet 例如 单击按钮(假设按钮名为“Register”)后,请求转到“actionFirst”Servlet 还有一个Servlet“actionSecond”,现在我想将请求转移到“actionSecond” 在Javascript函数中单击另一个按钮(假设按钮名为“编辑”)后,来自同一JSP文件的Servlet。我怎么能做到呢 你可以试试这个 <!-- create the form --> <form name="Form1"

我想从同一个JSP导航到多个servlet

例如


单击按钮(假设按钮名为“Register”)后,请求转到“actionFirst”Servlet

还有一个Servlet“actionSecond”,现在我想将请求转移到“actionSecond” 在Javascript函数中单击另一个按钮(假设按钮名为“编辑”)后,来自同一JSP文件的Servlet。我怎么能做到呢

你可以试试这个

 <!-- create the form -->
<form name="Form1" method="post">

<!-- Add the data entry bits -->
Your Name <input type="text" name="text1" size="10" /><br />

<!-- Add some buttons -->
<INPUT type="button" value="Button1" name=button1 onclick="return OnButton1();">
<INPUT type="button" value="Button2" name=button2 onclick="return OnButton2();">

<!-- close the form -->
</form>

您的名字
脚本看起来像

<script language="Javascript">
<!--
function OnButton1()
{
    document.Form1.action = "Page1.java"
    document.Form1.target = "_blank";    // Open in a new window
    document.Form1.submit();             // Submit the page
    return true;
}

function OnButton2()
{
    document.Form1.action = "Page2.java"
    document.Form1.target = "_blank";    // Open in a new window
    document.Form1.submit();             // Submit the page
    return true;
}
-->
</script>


这是一个非常奇怪的要求,但是要解决它,您需要使用Ajax,否则您的表单将被发布、页面重新加载或打开新窗口。最好是有两个连接了javascript函数的按钮。您甚至可以在按下一个按钮后禁用它,如果您需要特定的订单,还可以启用第二个按钮。

可能您需要第二个按钮、第二个表单或另一个servlet。通常不清楚您在问什么。我只是想知道如何从同一个JSP文件调用多个servlet?
<script language="Javascript">
<!--
function OnButton1()
{
    document.Form1.action = "Page1.java"
    document.Form1.target = "_blank";    // Open in a new window
    document.Form1.submit();             // Submit the page
    return true;
}

function OnButton2()
{
    document.Form1.action = "Page2.java"
    document.Form1.target = "_blank";    // Open in a new window
    document.Form1.submit();             // Submit the page
    return true;
}
-->
</script>