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