所以我只是在搞乱JSP并试图制作一个登录表单,现在当我输入“test”作为用户名和“test”作为密码时,它应该登录,因为该帐户是在数据库中创建的。而不是“登录”,它只显示文本“不正确的用户名:test”,然后在新行上显示从我编写的方法返回的数据库值,即“test”。
请帮我解决这个问题,它真的开始困扰我。
这是我的代码:
String userID = request.getParameter("username").trim();
String pass = request.getParameter("password").trim();
String corrUserID = MySQL.getString("SELECT username FROM users WHERE username='" + userID + "'", "username").toString();
String corrPass = MySQL.getString("SELECT password FROM users WHERE username='" + pass + "'", "password").toString();
if(corrUserID != "String" && corrPass != "String" && userID != "Username" && pass != "Password"){
if(userID == corrUserID){
if(pass == corrPass){
out.println("Logged in!");
response.sendRedirect("index.jsp");
}else{
out.println("Incorrect password.");
}
}else{
out.println("Incorrect username: " + userID + "<br/>" + corrUserID);
}
}else{
out.println("Please enter a valid username and password.");
}