繁体   English   中英

从html文件读取json数组并在servlet中打印值

[英]to read json array from html file and printing the values in servlet

我有一个从表单生成的JSON数组

<script type="text/javascript"> 
        $(function() {
            $('#btn').click(function() {
                var formData=JSON.stringify($('#sform').serializeObject());
                // $('#rValues').text(formData);
                $.get('Partition',"fdata="+formData,function(fJson) {                   

                    $.each(fJson, function(key,value) { 
                        if(fJson!=null){

                        }
                    });
                });
                $("#rValues").show();              
                return false;
            });
        });
        $.fn.serializeObject = function() {
            var o = {};
            var a = this.serializeArray();
            $.each(a, function () {
                if (o[this.name] !== undefined) {
                    if (!o[this.name].push) {
                        o[this.name] = [o[this.name]];
                    }
                    o[this.name].push(this.value || '');
                } else {
                    o[this.name] = this.value || '';
                }
            });
            return o;
        };
    </script>

我正在尝试读取和打印Partiton.java(servlet)中的整个表单值,但无法这样做。

 String data = request.getParameter("fdata");
    System.out.println(data);

您不会通过request.getParameter(“ fdata”)获得fdata

但是您将通过request.getParameter(“为字段指定的表单字段名称”)获得所有表单字段值。

在客户端 :将表单数据发送到servlet

$.ajax({
     url:'servlet',
     data: $("#form1").serialize(),
     success: function (data) {

    }
});

在Servlet上 :request.getParameter(“为表单字段指定的表单字段名称”)。

暂无
暂无

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

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