You are on page 1of 9

//validateUser.

jsp

<%--

Document : validateUser

Created on : Aug 29, 2016, 5:40:08 PM

Author : Administrator

--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>
<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>JSP Page</title>

</head>

<body>

<%@page import="java.sql.*;" %>

<%! String un,pw;%>

<%

un=request.getParameter("username");

pw=request.getParameter("password");

try{

Class.forName("com.mysql.jdbc.Driver");

Connection
con=DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/Student","root","patkar");

String sql="select * from Registration where username=? and password=?";

PreparedStatement ptst=con.prepareStatement(sql);

ptst.setString(1, un);

ptst.setString(2, pw);

ResultSet res=ptst.executeQuery();
if(res.next())

//

response.sendRedirect("index.jsp");

// out.print("hiieee");

else

out.print("Invalid User");

//response.sendRedirect("login.jsp");

}catch(Exception e)

{out.print(e);}

%>

</body>

</html>
//login.jsp

<%--

Document : login

Created on : Aug 29, 2016, 5:22:29 PM

Author : Administrator

--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"

"http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<title>Login</title>

</head>

<body>

<form action="validateUser.jsp" method="post">

<center>

<table>

<tr>

<td> Enter Username :


<td><input type="text" name="username" value="username">

</tr>

<tr>

<td>

Enter Password :

<td><input type="password" name="password" value="password">

</tr>

<tr>

<td>

<input type="submit" name="submit" value="Login">

</tr>

<h1></h1>

</table>

</center>

</form>

</body>

</html>
For invalid user

You might also like