Home  >  Article  >  Web Front-end  >  How to verify the uniqueness of users in the database with Ajax

How to verify the uniqueness of users in the database with Ajax

php中世界最好的语言
php中世界最好的语言Original
2018-04-04 15:31:081961browse

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:

How to verify the uniqueness of users in the database with Ajax

How to verify the uniqueness of users in the database with Ajax

How to verify the uniqueness of users in the database with Ajax

How to verify the uniqueness of users in the database with Ajax

##Then let’s get started,

Operation steps As follows

1. First we import the required packages and files

Json package:

How to verify the uniqueness of users in the database with Ajax

struts2 package:

How to verify the uniqueness of users in the database with Ajax

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

##ajax file upload + processing browser compatibility

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn