SPRING--MVC register user name for weight verification

Source: Internet
Author: User

SPRING--MVC register user name for weight verification

    Registration is to verify that the user name is duplicated. The Post method, when the form's User name text box loses focus, is specified by the Ajax method, and the method that is called when the @requestmapping specified URL is committed.

DAO mapping Code. Pass in an object, uname the property color with the object

<!--users duplicate name query--    <select id= "querybyuname" resulttype= "int" parametertype= "Com.bean.UsersBean" >         Select        count (*) from users where Uname=#{uname}    </select>

Service Layer Code:

/**      * Determine if the user name has     been      registered *@param      user@return         */  Public int haveusers (usersbean user);

  Controller code:

@Resource (name = "Usersservice")    PrivateIusersservice Usersservice; /*** The method that is called when the user name text box of the form loses focus, specified by the Ajax method, and @requestmapping the specified URL is submitted * *@paramUESR *@return     */@RequestMapping (Value= "/isvailduname", method ={Requestmethod.post}, produces= "Application/json;charset=utf-8")     Public@ResponseBodyintisvailduname (String uname) {Usersbean user=NewUsersbean ();        User.setuname (uname); returnusersservice.haveusers (user); }

Page JSP code:

<form action= "" method= "post" >         User name:<input type= "text" name= "uname" id= "uname" >        <div Id= "Div" ></div>         Password:<input type= "password" name= "UPass" >         <input type= "Submit" Value= "Register" >    </form>

jquery Code:

$ (function () {        $ ("#uname"). blur (function () {            $.post ("${path}/users/isvailduname.action ", {                uname: $ (this). Val ()            }, function (data) {                if (Data > 0) {                    $ ("#div"). HTML ("User name already exists! ");                    $ (this). Select ();                 Else {                    $ ("#div"). html ("OK");});        }     );

When you are done, remember to bring jquery code into the JSP page.

After running!!

    

    Organize your notes more. After all, I'm a bad memory person.

Or

    

SPRING--MVC register user name for weight verification

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.