Feature implementation:
Fill in the text box content in the JSP page, the cursor leaves the text box, in the corresponding place on this page to obtain the data corresponding to the change value in the database.
Servlet:
1Request.setcharacterencoding ("Utf-8");2PrintWriter out =Response.getwriter ();3 //Call the servlet layer to go to the database to find the same user name and return to other records in the page4String client_id = Request.getparameter ("client_id");5Clientservices clientservices =Newclientservices ();6 Try {7Thread.Sleep (2000);8}Catch(interruptedexception e) {9 e.printstacktrace ();Ten } OneClient client =Clientservices.findclientbyid (client_id); A if(Client! =NULL) { -Out.print (Urlencoder.encode (Client.getclient_name (), "Utf-8")); -}Else { theOut.print ("false"); - } - Out.flush (); -Out.close ();
Jquery:
1$ (document). Ready (function() {2$ ("#client_id"). Blur (function() {3 $.ajax ({4Type: ' POST ',5URL: ' servlet/validservlet?client_id= ' + $ ( This). Val (),6Data: ' client_id= ' + $ ("#client_id"). Val (),7Success:function(msg) {8 if(msg = = ' false ') {9Alert ("No this person");Ten}Else { One //utf-8 decoding to solve Chinese garbled characters A$ ("#clientInfo"). HTML (decodeURI (msg)); -$ ("#clientInfo"). attr ("value"), decodeURI (msg)); - } the } - }); - }); -});
Ajax validates database content and displays it in the page