本文实例讲述了jQuery+json实现的简易Ajax调用。分享给大家供大家参考,具体如下:
Userservlet.java代码:
添加对象
List userList = new ArrayList();
User user1 = new User("张三","男","18");
User user2 = new User("李四","19");
User user3 = new User("王五","20");
userList.add(user1);
userList.add(user2);
userList.add(user3);
PrintWriter out = response.getWriter();
String str = null;
try {
//帐号密码如果匹配则把list 返回给界面
if (request.getParameter("userName").equals("jquery")
&& request.getParameter("password").equals("ajax")) {
str = JSONObject.quote(JSONUtil.toJSONString(userList));
}
out.print(str);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
System.out.println("str "+str);
out.flush();
out.close();
}
}
帐号 jquery 密码 ajax
查询到的数据