JSP Part code:
<%@ Page ContentType="Text/html;charset=utf-8"language="Java" %><HTML><Head> <%@include File="/common/header.jsp"%> <title>User Management</title> <Scripttype= "Text/javascript"> functiondoverify () {//get an account of the interface var Account= $("#account"). Val (); //get the message text after the account varAccounttext=document.getElementById ("Accounttext"); //If the account input is not empty, execute the method if( Account!=""{$.ajax ({URL:"${basepath}nsfw/useraction_verifyaccout.action",//methods for background query validationdata:{"User.account": Account},//parameters to carryType:"Post", Success:function(msg) {//Add HTML to the message that returns to the foreground from the background if("true" !=msg) { //account already existsaccounttext.innerhtml= "<font color= ' red ' > Sorry,"+ Account+"has been registered, please replace! </font>" } Else{ //account does not existaccounttext.innerhtml= "<font color= ' green ' > Congratulations,"+ Account+"can register! </font>" } } }); } } </Script></Head><Bodyclass= "Rightbody"><TR> <TDclass= "tdbg"width= "200px">Account:</TD> <TD><S:textfieldname= "User.account"ID= "Account"onchange= "doverify ()"/> <spanID= "Accounttext"></span> </TD> </TR></Body>
Background code:
Public classUserdaoimplextendsBasedaoimpl<user>ImplementsUserdao {/*** Verify account Uniqueness*/@Override PublicList<user>Findobjectbyaccountandid (string ID, string account) {StringBuilder hqlstr=NewStringBuilder ("from User t WHERE t.account =?")); if(Stringutils.isnotblank (id)) {hqlstr.append ("and t.id=?"); } Query Query=getsession (). CreateQuery (Hqlstr.tostring ()); Query.setparameter (0, account); if(Stringutils.isnotblank (id)) {query.setparameter (1, id); } returnquery.list (); }
:
AJAX-based authentication for user name uniqueness in jquery