动作表单不止一个Servlet [英] Action Form more than one Servlet
问题描述
尽管听起来可能有些愚蠢,但我仍然在问这个概念性和逻辑性(据我所知:)):
Though it may sound a bit silly,still I'm asking this conceptual and logical(as far as foe me :)) question :
在一个jsp页面中,我可以将其表单数据发送到多个Servlet吗?.
In a jsp page Can I send it's form data to more than one Servlet.. like :
form action="home","car" method="post" name="f1"
或
form name='form' method='POST' action='car','home'
任何输入.....//
Any inputs.....//
推荐答案
在客户端,您可以通过指定两个不同的目标窗口来保存响应,从而通过javascript将表单提交到两个不同的servlet.
On the client side, you can do submit the form to two different servlets through javascript, by specifying two different target windows to hold the response.
HTML:
HTML:
<IFRAME id="firstResult" name="firstResult"></IFRAME>
<IFRAME id="secondResult" name="secondResult"></IFRAME>
JavaScript:
Javascript:
function submitForm() {
var form = document.getElementById("myForm");
form.action = "/first-servlet";
// Target is the name of the iframe to hold the response from first servlet.
form.target = "firstResult";
form.submit();
form.action = "/second-servlet";
// Target is the name of the iframe to hold the response from second servlet.
form.target = "secondResult";
form.submit();
}
然后,您应该具有处理程序来捕获IFRAME的onload事件,以处理来自Servlet的响应.
Then you should have handlers to capture the IFRAME's onload event to process the responses from the servlet.
这篇关于动作表单不止一个Servlet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!