Userservlet. java code packagecom. iss. servlet; importorg. json. JSONException; importorg. json. JSONObject; importcom. iss. pojo. User; importcom. iss. util. JSONUtil; publicclassU
Userservlet. java code
Package com. iss. servlet;
Import org. json. JSONException;
Import org. json. JSONObject;
Import com. iss. pojo. User;
Import com. iss. util. JSONUtil;
Public class UserServlet extends HttpServlet {
Public void doGet (HttpServletRequest request, HttpServletResponse response)
Throws ServletException, IOException {
DoPost (request, response );
}
Public void doPost (HttpServletRequest request, HttpServletResponse response)
Throws ServletException, IOException {
Response. setContentType ("text/html; charset = UTF-8 ");
// Add objects to a list
List UserList = new ArrayList ();
User user1 = new User ("Zhang San", "male", "18 ");
User user2 = new User ("Li Si", "male", "19 ");
User user3 = new User ("Wang Wu", "male", "20 ");
UserList. add (user1 );
UserList. add (user2 );
UserList. add (user3 );
PrintWriter out = response. getWriter ();
String str = null;
Try {
// Return the list to the interface if the Account Password Matches
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 ();
}
}
Html code
Account jquery password ajax
Queried data