简体   繁体   English

通过两个动作和一个按钮提交创建表单

[英]Create form with two action and one button submit

In the form I want call one of two Servlet if an event occurred.. Why does it not works? 如果发生事件,我想以这种形式调用两个Servlet之一。为什么不起作用?

<form method="post" action="<%=tipo_ricerca.equals('normale') ? VisualizzaRecensioniServlet : VisualizzaRecensioniRicercaVotoServlet;%>">
<a href="javascript:;" onclick="parentNode.submit()">Start</a>
</form>

You are trying to mix javascript and Java in a way that makes no sense. 您正试图以一种毫无意义的方式混合使用javascript和Java。

First of all, you don't even have a submit button; 首先,您甚至没有提交按钮。 you have a regular link that is not even formatted correctly. 您有一个常规链接,甚至没有正确设置格式。 Replace 更换

<a href="javascript:;" onclick="parentNode.submit()">Start</a>

with

<input type='submit' value='Start' />

Or, since you don't have any values in your form, you don't really need a form, and thus could just use a link like this: 或者,由于您的表单中没有任何值,因此您实际上不需要表单,因此可以使用如下所示的链接:

<a href="<%=tipo_ricerca.equals('normale') ? VisualizzaRecensioniServlet : VisualizzaRecensioniRicercaVotoServlet;%>">Start</a>

Secondly, if you want to call another servlet from Java, use response.sendRedirect() or something of that nature. 其次,如果要从Java调用另一个servlet,请使用response.sendRedirect()或类似的性质。 If you want to call the servlet from Javascript, <%=somevar%> is not of any use for that since the server-side processing is over before Javascript begins running on the client. 如果要从Javascript调用servlet,则<%=somevar%>没有任何用处,因为服务器端处理已在Javascript开始在客户端上运行之前结束。 Unless your intent was to set which servlet to use while the server-side code was being processed. 除非您的意图是设置在处理服务器端代码时使用哪个servlet。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM