如何将请求从同一个JSP文件发送到多个Servlet?

时间:2014-11-08 12:20:06

标签: java javascript jquery jsp servlets

我想从同一个JSP导航到多个Servlet。

EG。

<form name="sample"  action = "actionFirst"  method="get">

点击按钮后(假设按钮名称为&#39;注册&#39;)请求进入&#39; actionFirst&#39;的servlet。

有anather Servlet&#39; actionSecond&#39;现在我想将请求转移到&#39; actionSecond&#39; 从Javascript函数单击anather按钮(假设按钮名称为&#39; Edit&#39;)后来自同一JSP文件的Servlet。我该如何实现这一目标?

2 个答案:

答案 0 :(得分:1)

你可以试试这个。

 <!-- 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>

答案 1 :(得分:0)

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

相关问题