Simple Ajax call implemented by jQuery + json

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.