How to execute a method when exiting a input
text. Example I will make a registration at the moment of registering as a user I want to check if that name is available to be used, being that it can not accept repeated users, to avoid that the check is at the time of sending all the data I would like to do this verification when the user finishes typing and goes to the next field to fill in.
I already did the part of Servlet
and method DAO
, but the part of jsp
I'm kind of lost I see a lot of people talking about ajax
, but I'd like to avoid using it.
My servlet
if(funcao.equals("verificaUsuario")){
String usuario = request.getParameter("user");
boolean verifica = log.verificarUsuario(usuario);
if(verifica = true){
request.setAttribute("O nome '"+usuario, "' este indisponível para uso, por gentileza tente outro nome para realizar o cadastro." );
}else{
request.setAttribute("Prabéns! O nome '"+usuario, "' este disponível para uso." );
}
RequestDispatcher rd = request.getRequestDispatcher("v_login_cad.jsp");
rd.forward(request, response);
}
My DAO
public boolean verificarUsuario(String nome) {
String sql = "select * from login where log_nome=? ";
try {
PreparedStatement ps = con.prepareStatement(sql);
ps.setString(1, nome);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
return true;
} else {
return false;
}
} catch (SQLException e) {
//throw new RuntimeException("Erro 1_D " + e);
Logger.getLogger(Login.class.getName()).log(Level.SEVERE, null,"Erro 2_D " + e);
}
return false;
}