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:
##Then let’s get started,Operation steps are as follows
1. First, we import the required packages and files Json package: struts2 package: Introduce jquery-2.1.1.min .js files.<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<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>
<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>
//验证用户的唯一性 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(); }
<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>
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!