<%
String userName = request.getParameter("username");
String password = request.getParameter("password");
String rm_me = request.getParameter("rm_me");
String rm_uname = request.getParameter("rm_uname");
if (userName != null && password != null) {
if (rm_me != null) {
Cookie ckU = new Cookie("username", userName);
Cookie ckP = new Cookie("password", password);
response.addCookie(ckP);
} else {
if (rm_uname != null) {
Cookie ckU = new Cookie("username", userName);
}
}

Cookie[] cookies = request.getCookies();
if (cookies != null) {
for (int i = 0; i < cookies.length; i++) {
if (cookies[i].getName().equals("username")) {
userName = cookies[i].getValue();
}
if (cookies[i].getName().equals("password")) {
password = cookies[i].getValue();
}
}
}
%>

However, on testing the page, the user had to retype the username each time the
Login page was loaded.but i want the user not to type the password and username everytime when they log on.
can someone assist mi to identify the error i have with my coding1

try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn = DriverManager.getConnection("jdbc:odbc:mydsn","sa","password@123");
String sql = "select customer_id, fname, lname, email_id, phone_number from customer_details where user_name=? and password=?";
PreparedStatement stmt;
ResultSet rs = stmt.executeQuery();
if (rs.next()) {
session.setAttribute("customerId", rs.getString(1));
session.setAttribute("userName", userName);
session.setAttribute("fName", rs.getString(2));
session.setAttribute("lName", rs.getString(3));
session.setAttribute("emailId", rs.getString(4));
session.setAttribute("phoneNumber", rs.getString(5));
conn.close();
%>
<jsp:forward page="welcome.jsp" />
<%} else {%>
Sorry! You have entered an invalid username or password. Please try again.
<%}
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}

i want the procedeng code to display error message when the wrong password and username are entered and if the correct password and username are entered then the user can logg on.However, the Login page displays an error message indicating failure to login, even when the correct username and password combination is entered.can someone help me to Identify the error

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.