validation.java
try
{
conn = dsEvent.getConnection();
String userCheck = \"select * from customer\";
stmt = conn.createState
Why are you iterating through whole resultset
and validating if user is present or not instead try changing your select
query to check if particular user is present in your database or not.
To do that try below code
String email = request.getParameter("email");
String password = request.getParameter("password");
String userCheck = "select * from tableName where username = ? AND password = ?";
PreparedStatement ps = con.prepareStatement(userCheck);
ps.setString(1, email);
ps.setString(2, password);
ResultSet rs = ps.executeQuery();
And than just check whether resultset
is empty or not.
To check resultset is empty or not put below code:
if(rs.isBeforeFirst()) {
request.getSession().setAttribute("email",email);
response.sendRedirect("success.jsp");
} else {
request.setAttribute("error", "Invalid Username & Password");
request.getRequestDispatcher("index.jsp").forward(request, response);
}
For isBeforeFirst()
method look here.
Also change index.jsp
to show error message
<%=request.getAttribute("error")!=null ? request.getAttribute("error"): "" %>