I am making a web application using Spring MVC and jsp. I am quite new to this and really struggling to find an approach to validating a username from DB before submitting the form. Here is a demo of the kind of thing am looking for http://www.bitrepository.com/demo/username-checker/
Would appreciate any help given. Thank you
You can find a lot of answers if you search "Spring MVC form validation" on Google. For example, spring official tutorial: https://spring.io/guides/gs/validating-form-input/
Another example on codejava.net: http://www.codejava.net/frameworks/spring/spring-mvc-form-validation-example-with-bean-validation-api
Followed this this tutorial:
http://www.mkyong.com/spring-mvc/spring-4-mvc-ajax-hello-world-example/
Thank you very much @YohanesGultom
you can check username by jquery validation
$("#myform").validate({
rules: {
email: {
required: true,
remote: {
url: 'checkUserName',
data: { userName: $('#username').val()},
dataFilter: function(data) {
var json = JSON.parse(data);
console.log(data);
}
}
},
messages: {
email: {
required: "This field is required",
remote: "Email address already in use. Please use other email."
}
}
});
and in your controller add this method :
@requestMapping("checkUserName")
@responseBody
public boolean checkUser(@requestParam("userName") String userName){
return // method return bolean if user exist or non in database.
}