gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 11:28:52 25 4
gpt4 key购买 nike

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

例如。

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

单击按钮后(假设按钮名称为“注册”),请求将转到“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>

关于java - 如何将请求从同一个 JSP 文件发送到多个 Servlet?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26817059/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com