Home > Web Front-end > JS Tutorial > 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中世界最好的语言
Release: 2018-04-04 15:31:08
Original
1999 people have browsed it

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>
Copy after login
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>
 
Copy after login
  

名字:

     

           
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();
 }
Copy after login
5. Finally, write the Struts.xml file

<package>  
 <action>
  <result>/login.jsp</result>
 </action>
</package>
Copy after login
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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template