我正在使用JSP Servlet和MySQL数据库创建登录页面应用程序。但是我的应用程序没有显示任何错误。
package controller;
import java.io.IOException;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@WebServlet("/LoginController")
public class LoginController extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String un=request.getParameter("user");
String pw=request.getParameter("pass");
// Connect to mysql(mariadb) and verify username password
try {
Class.forName("com.mysql.jdbc.Driver");
// loads driver
Connection c = DriverManager.getConnection("jdbc:mysql://localhost:3306/mylogin?" + "username=root&password="); // gets a new connection
PreparedStatement ps = c.prepareStatement("select usernmae,password from login where username=? and password=?");
ps.setString(1, un);
ps.setString(2, pw);
ResultSet rs = ps.executeQuery();
while (rs.next()) {
response.sendRedirect("welcome.jsp");
return;
}
System.out.println("invalid user");
return;
} catch (ClassNotFoundException | SQLException e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
您是否检查了服务器端日志?您的SQL语句中似乎有一个错字。您也可以尝试删除代码中的return
语句。