如何使用一个提交按钮保存多个表单数据 [英] How to save multiple form data using one submit button

查看:354
本文介绍了如何使用一个提交按钮保存多个表单数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的jsp页面中,我有两种形式.一种形式是进入save_product servlet,另一种形式是进入save_images servlet.只有一个提交按钮.首先单击提交按钮时,我要保存产品,然后再保存图像.

In my jsp page I have two forms.one form action goes to save_product servlet and other one is goes to save_images servlet. There is only one submit button. when click submit button first I want to save products and then want to save images.

我使用jQuery和Request.getRequestDispatcher(String).forward()进行了尝试.但未成功.

I tried it using jQuery and Request.getRequestDispatcher(String).forward() .but it is not succeeded.

这是我的jsp:

    <button type="submit" class="btn btn-default" id="formsave1">Save</button>

    <div class=container>
     <div class="panel">
        <form action="../save_product" method="POST"><button type="submit" id="formsave2" ></button> 
    </div>
      <div class="panel">
        <form action="../save_images" method="POST" enctype="multipart/form-data">
             <button type="submit" id="formsave3"></button>
</div>
    </div>

产品保存servlet:

Product save servlet:

req.getRequestDispatcher("save_images").forward(req, resp);

jQuery:

  $(document).ready(function () {
                $(formsave1).on("click", function (e) {
                    alert('CLICKED 1');
                    $('#formsave2').click();
                       alert('CLICKED 2');
                });

推荐答案

您的代码不足以完全识别问题.我无法发现问题.

Your code is insufficient to identify the problem completely. I cannot spot the issue.

但是,根据您的html代码,我猜这两个servlet都在同一个包中.在这种情况下,您可以直接调用save_imagesdoPost()doGet()方法,因为它们都具有protected访问修饰符.

However, as per your html code I guess that both servlets are in the same package. In that case you may directly call the doPost() or doGet() methods of save_images as they both have protected access modifier.

根本不需要使用Requestdispatcher.

There's no need to use the Requestdispatcher after all.

new save_images().doPost(req, resp);

这篇关于如何使用一个提交按钮保存多个表单数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆