1.mysql数据库
2.json的六个架包导入
3.Servlet后台dopost方法
查询到list对象之后:
JSONArray jsonArray = JSONArray.fromObject(list);
response.getWriter().print(jsonArray.toString());
进行json转化
4.JSP前台页面
function sel(){
$.ajax({
type: "POST",
url: "Servlet",
dataType:"json",
success: function(data){
var str = "";
str = "
用户名 密码
";
$.each(data, function(index, item) {
alert(index);
str += "
" + item.name + " "
+ item.password + "
";
});
str += "
";
$("#data").html(str);
}
});
}
5.输出结果: