【问题标题】:Multiple form submition in spring mvc 3.0spring mvc 3.0中的多个表单提交
【发布时间】:2013-07-25 07:51:57
【问题描述】:

我想在注册表单(如预览页面)中显示用户输入的数据,以确认输入数据的正确性,如果他们接受,则该数据应进入数据库。

这是我的控制器代码:

@RequestMapping( value="/catalogue/FormPreview.action", method=RequestMethod.POST)
public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command,CatalogueBase catalogueBase) throws Exception {

        if(catalogueBase.getTitleNumber()!= null)
        {
            request.setAttribute("titleNo", catalogueBase.getTitleNumber());
            request.setAttribute("title", catalogueBase.getTitle());
            request.setAttribute("name", catalogueBase.getName());
            request.setAttribute("address", catalogueBase.getAddress());
            request.setAttribute("email", catalogueBase.getEmail());

                     .....

            return new ModelAndView("catalogue/catalogueFormPreview","catalogueBase",catalogueBase);
        }
        else
        {
            return create(catalogueBase);
        }
    }

    @RequestMapping( value="/catalogue/create.action", method=RequestMethod.POST)
        public ModelAndView create(@ModelAttribute CatalogueBase catalogueForm) throws Exception {  
            ModelAndView mvc = null;

            try{

                List<CatalogueBase> catalogueBases =  new ArrayList<CatalogueBase>(); //getCatalogueBase(request);
                catalogueBases.add(catalogueForm);
                List<CatalogueBase> catalogueBaseList = catalogueService.create(catalogueBases);
                mvc =   new ModelAndView("catalogue/catalogueList");

            } catch (Exception e) {
                e.printStackTrace();
            }
            return mvc;
        }

我使用 EL 将预览页面显示为 jsp:

    Title NO : ${titleNo}
    Title : ${title}
    ......
    ......

   <a onclick="doAjaxPost();">Confirm Data<span class="icon icon44"></a>

在 jsp 的头部,我将 ajax 称为:

<script>
function doAjaxPost() {
    var name = $('#name').val();
    var education = $('#education').val();
    var str = $("#form").serialize();

    $.ajax({
        type: "POST",
        url: "../catalogue/create.action",
        data: str,
        success: function(response){
         alert("Record Added Successfully");
         },
         error: function(e){
             alert('Error: ' + e);
         }
    });
};

它在预览页面上显示数据,但点击确认数据后,(预览页面中的超链接) 它将空值发送到创建方法(第二种方法)请任何人都可以告诉它为什么发送空值以及我如何解决这个问题

谢谢。

【问题讨论】:

    标签: spring jsp spring-mvc


    【解决方案1】:

    在预览页面中,您只显示文本,您需要在预览页面中以隐藏的方式获取您的数据(或通过任何其他方式,例如如果存在大量条目则保存在会话中等)。这样当你确认后提交时,就可以读取所有参数了。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-03-08
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      • 2014-06-22
      相关资源
      最近更新 更多