<blockquote> <p>Blockquote</p> </blockquote> <p><%@page contentType="text/html"%> <%@page pageEncoding="UTF-8"%> <%@page import="java.sql.Connection" %> <%@page import="java.sql.DriverManager" %> <%@page import="java.sql.Statement" %> <%@page import="java.sql.ResultSet" %> <%@page import="java.sql.PreparedStatement" %> <%@page import="java.sql.SQLException" %></p> <p><html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Login</title> </head> <% String userName = request.getParameter("username"); String password = request.getParameter("password"); String rm<em>me = request.getParameter("rm</em>me"); String rm<em>uname = request.getParameter("rm</em>uname");</p> <pre class="prettyprint"> 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); } } 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(); } } %> <body> <p> </p> <p> </p> <p> </p> <p> </p> <% 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(); } } } %> <form name="LoginForm" id="LoginForm" method=post Action="login.jsp"> <table width="70%" align="center" border="1"> <tr> <td><img src="logo.jpg"></img></td> <td>Lets conserve our environment</td> </tr> <tr> <td align="center">User Name</td> <td><input type="text" name="username" maxlength="50" value="<%=(userName==null?"":userName)%>"/></td> </tr> <tr> <td align="center">Password</td> <td><input type="password" name="password" maxlength="100" value="<%=(password==null?"":password)%>"/></td> </tr> <tr> <td> </td> <td> <input type="submit" name ="login" value="Login" /> </td> </tr> <tr> <td align="center"> <input type="checkbox" name="rm_uname" value="RememberUsername" />Remember Username </td> <td> <input type="checkbox" name="rm_me" value="RememberMe" />Remember Me </td> </tr> </table> </form> </body> </code></pre> <p></html></p> <blockquote> <p>Blockquote</p> </blockquote> <p>can someone help to identify the error because even when the username and password are provided the error message appers indicating failure to loggin. </p>
Please visit the following links:
http://www.roseindia.net/jsp/loginbean.shtml
Ads