2
I’m creating a connection to the Java database like this:
try{
Class.forName("org.postgresql.Driver");
Connection con = DriverManager.getConnection("jdbc:postgresql://localhost/projeto","postgres","754753");
if(request.getParameter("user") != null)
{
//caminho para chegar até a tabela no BD
Statement st = con.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_READ_ONLY);
ResultSet rs = st.executeQuery("select * from login where log_usuario = '"+
request.getParameter("user")+"' and log_senha = '"+
request.getParameter("pass")+"'");
if(rs.next())
//response.sendRedirect("paginas/home.jsp");
else
out.println("Não Logado");
}
}
catch(ClassNotFoundException ClassError){
out.println("Driver não encontrado "+ClassError);
}
catch(SQLException SQLError){
out.println("Erro de conexão com o banco de dados");
}
I want to send it to ajax to validate with the $.ajax({});
.
Within the success
I want to have 3 conditions that would be:
- enter your user and password
- invalid username or password
- login done, please wait...
Sort of like this:
$('form').submit(function(){
var login = $(this).serialize();
$.ajax({
url:
data:
type:
success: function(resposta){
if(resposta == 'erroempty'){
$('.msg').empty().hmtl('<p class="aviso">Informe seu usuário e senha!</p>').fadeIn('slow');
}else if(resposta == 'errosenha'){
$('.msg').empty().hmtl('<p class="erro">Erro ao logar! Dados não conferem!</p>').fadeIn('slow');
}else if(resposta == 'success'){
$('.msg').empty().hmtl('<p class="sucesso">Login efetuado, aguarde...</p>').fadeIn('slow');
}
},
beforeSend: function(){
$('.loginbox h1 img').fadeIn('fast');
},
complete: function(){
$('.loginbox h1 img').fadeOut('fast');
}
});
return false;
});
How do I get Java to pass the 3 information (erroempty, erroneous password and Success) and what I would put in url
, data
and type
?
I understood, so I put it like this: url: 'index.jsp', data: login, type: 'POST', but on the question of the database answer, how do I({})
– Claudemir Simons
at query return, you can use that to send the JSON object, if(rs.next()) { send object here}
– Isvaldo Fernandes
Thanks for responding, so... I don’t know how I do to send, could give me a few tips, as I could do to send?
– Claudemir Simons