Home  >  Article  >  Web Front-end  >  Ajax verify user uniqueness

Ajax verify user uniqueness

亚连
亚连Original
2018-05-24 09:55:011676browse

This article mainly introduces the uniqueness of Ajax verification users and the verification environment Ajax Jquery Json struts2. Interested friends can refer to it

For beginners, learn the practical practice of Ajax verification of user uniqueness It is to consolidate the basic knowledge of Ajax, Jquery, Json and Struts2. The specific content is as follows

Browse the renderings:

Ajax verify user uniqueness

Ajax verify user uniqueness

Ajax verify user uniqueness

Ajax verify user uniqueness

##Then let’s get started,

Operation steps are as follows

1. First, we import the required packages and files

Json package:

Ajax verify user uniqueness

struts2 package:

Ajax verify user uniqueness

Introduce jquery-2.1.1.min .js files.

<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>

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 CSS styles to it to make it more beautiful. (I only did it briefly, a bit low)

<p class="row">
 <h1>Ajax+Jquery验证用户的唯一性</h1>
 <form action="" method="post">
  <h3>名字:</h3>
  <input type="text" id="name" class="form-control" name="user.name" id="name" placeholder="请输入你的用户名">
  <br><br>
  <input type="submit" class="btn btn-success" value="验证用户的唯一性"/>    
  <span id="namemsg"></span>
 </form>
</p>

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 name="user" namespace="/" extends="struts-default">  
 <action name="user_*" class="com.ddge.action.UserAction" method="{1}">
  <result name="error">/login.jsp</result>
 </action>
</package>

The above is me I compiled it for everyone, I hope it will be helpful to everyone in the future.

Related articles:

How Ajax calls the restful interface to transmit Json format data (with code)

Boa server Ajax and cgi communication under (graphic tutorial)

Ajax Struts2 implements verification code verification function (graphic tutorial)

The above is the detailed content of Ajax verify user uniqueness. 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