Swdynasty_
for t
2020-04-21 20:06

通过jquery的ajax的getJSON()方法,向后端返回js字符串数组,servlet接收到空值

  • spring
  • java
  • json
  • ajax
  • jquery

前端代码

function insert_student(){
                    var select = new Array();
                    var text = $(" .have_input ");
                    //console.log( $("text["+z+"] : input"));
                     for(var i= 0; i<text.length; i++){
                         if($($(" .have_input ")[i].children[0]).prop("checked") == true){
                             //console.log(i);
                             select.push($(" .have_input ")[i].nextSibling.innerHTML);
                             //select.push($("trrr[i] td:eq(1)").innerHTML);
                         }
                     }
                     console.log(select);

                    $.getJSON("insertStudentSvl",
                            {"students":select},
                            function (result){

                            }
                            )
                }

后端代码

request.setCharacterEncoding("utf-8");
        response.setCharacterEncoding("utf-8");
        response.setContentType("text/html; charset=UTF-8");

        String a= request.getParameter("students");
        PrintWriter out = response.getWriter();
        StudentDao dao= new StudentDao();
        //ArrayList<StudentEntity> students= new ArrayList<StudentEntity>();
        System.out.println(a);

select数组中的每个元素都是一个字符串,我想知道后端怎么处理能得到该值,感谢!

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

1条回答