发表评论
学生类:
public class Student { Integer id; //编号 String name;//姓名 String gender;//性别 public Student(Integer id, String name, String gender) { super(); this.id = id; this.name = name; this.gender = gender; } public Student() { super(); } }
后台controller层代码使用的是ajax调用
String str=JSONArray.fromObject(list).toString(); PrintWriter pw = res.getWriter(); pw.print(str); pw.flush(); pw.close();
jsp使用ajax访问后台接收json数据并使用$.each方法进行遍历json
$.ajax({ url : "controller地址", type : "post", dataType : "json", async : false, data : {"complaint_type_code" : complaint_type_code}, success : function(data) { //使用$.each遍历json数据 $.each(data,function(index,context){ //使用context.属性的方式进行获取数据 alert("姓名:"+context.name+"--性别:"+context.gender); }); } });