How Ajax verifies the uniqueness of users
This article mainly shows you "Ajax how to verify the uniqueness of users", the content is easy to understand, clear, hope to help you solve your doubts, the following let the editor lead you to study and learn "Ajax how to verify the uniqueness of users" this article.
The details are as follows
Browse the effect picture:
Then here we go. The steps are as follows.
1. First of all, let's import the required packages and files.
Json package:
Struts2 package:
Import the jquery-2.1.1.min.js file.
two。 Then, we need to configure the Struts2 filter in the web.xml file
Struts2 org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter struts2 / *
3. Then, start writing our login.jsp page, of course, you can add some CSS style to it to make it more beautiful. (I just did it briefly, a little bit Low)
Ajax+Jquery verifies the unique name of the user:
4. Then we started writing Action.
/ / verify the uniqueness of the user public void isexist () throws IOException {boolean exist = name.equals ("Zhang San"); JSONObject result=new JSONObject (); if (exist) {result.put ("exist", true);} else {result.put ("exist", false);} ServletActionContext.getResponse (). SetContentType ("text/html;charset=utf-8"); PrintWriter out=ServletActionContext.getResponse (). GetWriter (); out.println (result.toString ()); out.flush () Out.close ();}
5. Finally, write the Struts.xml file
/ login.jsp above is all the content of the article "how Ajax verifies the uniqueness of users". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!