Login Page
Hiii...
i have been workin on the login page..i have to take the username n password as input n check it frm d data base...
m using the ms access data base...
i have to do the server side validations...
but i am unable to do the validations..
here's my code...
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<%@ page import="java.sql.DriverManager"%>
<%@page import="java.sql.*"%>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String Username = "";
String Password = "", pass = "";
Username = request.getParameter("userName");
Password = request.getParameter("passWord");
try {
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
// set this to a MS Access DB you have on your machine
String filename = "test.mdb";
String database = "jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=";
database += filename.trim() + ";DriverID=22;READONLY=true}"; // add on to the end
// now we can get the connection from the DriverManager
Connection con = DriverManager.getConnection(database, "", "");
Statement stmt = con.createStatement();
ResultSet rs = stmt
.executeQuery("select password from login WHERE username = '"
+ Username + "'");
//s.execute("select username,password from test");
//ResultSet rs = s.getResultSet();
while (rs.next()) {
pass = rs.getString(1);
out.print(pass);
if (Password.equals(pass)) {
out.print("Welcome" + Username);
} else {
out.print("Sorry");
}
}
stmt.close();
} catch (Exception e) {
System.out.println("Error: " + e);
}
%>
</body>
</html>
i am nt able to print the Welcome message...
every time its going into the else loop...
plz have a look on this issue..thnx...
Deepak
|