简体   繁体   English

JSP表单和Servlet

[英]JSP Form and Servlet

I have a form in a JSP page, which show a confirm window in javascript before submitting the form. 我在JSP页面中有一个表单,该表单在提交表单之前在javascript中显示了一个确认窗口。 I want to do that when the user clicks ok, the servlet handle that "event" and make an action, but only if the user click ok. 我想在用户单击“确定”时执行此操作,servlet会处理该“事件”并执行操作,但前提是用户单击“确定”。 I have some idea, but i don't know how can i complete it 我有个主意,但我不知道该如何完成

My Form.jsp 我的Form.jsp

var conf=confirm("¿Está seguro que desea enviar la información ?);
if(conf==true){
                document.getElementById("EIBSBTN").style.visibility='hidden';
                //some field or variable that serves like a flag
                return true;
            }else{
                alert("Ha cancelado en envio de la información !!");
                //some field or variable that serves like a flag
                document.getElementById("EIBSBTN");
                return false;

My servlet.java 我的servlet.java

If (field or variable == true)
{
make something;
else
make something else;
}

Thanks in advance 提前致谢

PD Sorry for my bad english, but i'm struggling :D PD对不起,我的英语不好,但是我在挣扎:D

If I understand your question, you could call the javascript function in the obSubmit handler for your form . 如果我了解您的问题,则可以在表单的obSubmit处理程序中调用javascript函数。 If you click okay the form will submit, if you don't (because you return false) it won't. 如果单击“确定”,则表单将提交,如果您不提交(因为返回false),则不会提交。 The servlet will not be called if the form isn't submitted. 如果未提交表单,则不会调用servlet。

you could do something like this: 您可以执行以下操作:

<form method="post" action="yourservlet" onsubimt="return confirm()">
  <input type="submit" value="submit" />
</form>

<script>
  var conf=confirm("¿Está seguro que desea enviar la información ?);
  if(conf==true){
       document.getElementById("EIBSBTN").style.visibility='hidden';
            //some field or variable that serves like a flag
            return true;
    }else{
       alert("Ha cancelado en envio de la información !!");
      //some field or variable that serves like a flag
       document.getElementById("EIBSBTN");
        return false;
   }

This way the request will only be sent to the servlet if the user click the ok button. 这样,仅当用户单击“确定”按钮时,请求才会发送到Servlet。 Otherwise, your form will not be submitted to the servlet. 否则,您的表单将不会提交到servlet。

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

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