AJAX-based authentication for user name uniqueness in jquery

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.