Java 注册用户表单的时候,先判断数据库里面是否用户已存在,存在的话,不准提交,想要用Ajax实现,怎么做啊
------解决方案--------------------
- JScript code
$("#username").blur(function(){ var username = $("#username").val(); if(username == ""){ $("#c_username").html("<img src='images/NO.png'> "); }else{ $.post("checkUsernameAction.action", {"username":username}, function(data){ if(data == "Y"){ $("#c_username").html("<span><img src='images/OK.png'></span>"); username_flag = true; }else if(data == "N"){ $("#c_username").html("<span><img src='images/NO.png'></span>"); } }); } });
------解决方案--------------------
public boolean checkUsers(String username) {
Session session=sessionFactory.getCurrentSession();
List<User> users=null;
Query query= session.createQuery("from User where username="+username);
users=query.list;
if(null!=users && users.size>0){
return true;
}else{
return false;
}
}