Home > Article > Web Front-end > How to verify the uniqueness of users in the database with Ajax
This time I will show you how Ajax verifies the uniqueness of users in the database. What are the precautions for Ajax to verify the uniqueness of users in the database. The following is a practical case, let's take a look.
For beginners, the actual practice of learning Ajax to verify user uniqueness is to consolidate the basic knowledge of Ajax, Jquery, Json and Struts2. The specific content is as follows
Browse the rendering:
##Then let’s get started,
Operation steps As follows
1. First we import the required packages and filesJson package: struts2 package: Introduce the jquery-2.1.1.min.js file.2. Then, we need to configure the Struts2 filter in the web.xml file
<filter> <filter-name>struts2</filter-name> <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class> </filter> <filter-mapping> <filter-name>struts2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>3. Then, start writing our login.jsp page, of course you can add some to it CSS styles to make it more beautiful. (I only did it briefly, a bit low)
<p> </p><h1>Ajax+Jquery验证用户的唯一性</h1>4. Then, we started writing Action.
//验证用户的唯一性 public void isexist() throws IOException { boolean exist = name.equals("张三") ; 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
<package> <action> <result>/login.jsp</result> </action> </package>I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website! Recommended reading:
How to pass multiple parameters using ajax
The above is the detailed content of How to verify the uniqueness of users in the database with Ajax. For more information, please follow other related articles on the PHP Chinese website!