JSP program to validate a login page
<%@ page import="java.sql.*" %>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%
Connection conn;
int i;
PreparedStatement psmt;
Statement stmt;
ResultSet rs;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
JSP Page
</title>
</head>
<body>
<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","tiger");
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from usertab where userid='"+request.getParameter("loginid")+'"
and password='"+request.getParameter("password")+'"");
if(rs.next())
{
resopnse.sendRedirect("homepage.jsp");
}
else
{
out.println("invalid user id and password");
}
}
catch(Exception e)
{
out.println("" +e.toString());
}
%>
</body>
</html>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>
<%
Connection conn;
int i;
PreparedStatement psmt;
Statement stmt;
ResultSet rs;
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>
JSP Page
</title>
</head>
<body>
<%
try
{
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","tiger");
stmt=conn.createStatement();
rs=stmt.executeQuery("select * from usertab where userid='"+request.getParameter("loginid")+'"
and password='"+request.getParameter("password")+'"");
if(rs.next())
{
resopnse.sendRedirect("homepage.jsp");
}
else
{
out.println("invalid user id and password");
}
}
catch(Exception e)
{
out.println("" +e.toString());
}
%>
</body>
</html>
No comments:
Post a Comment