0% found this document useful (0 votes)
5 views4 pages

WT Exp 11

Uploaded by

Akul Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views4 pages

WT Exp 11

Uploaded by

Akul Kumar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Experiment-11

Objective: Write a JSP which insert the details of the 3 or 4 users who register with the web
site by using registration form. Authenticate the user when he submits the login form using the
user's name and password from the database.

Code:
Login.html:

<html>

<body>

<center><h1>XYZ Company Ltd.</h1></center>

<table border="1" width="100%" height="100%">

<tr>

<td valign="top" align="center"><br/>

<form action="auth.jsp"><table>

<tr>

<td colspan="2" align="center"><b>Login Page</b></td>

</tr>

<tr>

<td colspan="2" align="center"><b>&nbsp;</td>

</tr>

<tr>

<td>User Name</td>

<td><input type="text" name="user"/></td>

</tr>

<tr>

<td>Password</td>

<td><input type="password" name="pwd"/></td>

</tr>

<tr>
<td>&nbsp;</td>

<td>&nbsp;</td>

</tr>

<tr>

<td colspan="2" align="center"><input type="submit" value="LogIN"/></td>

</tr> </table>

/form>

</td>

</tr>

</table>

</body>

</html>

Auth.jsp:

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

<html>

<head>

<title>

This is simple data base example in JSP</title>

</title>

</head>

<body bgcolor="yellow">

<%!String uname,pwd;%>

<%

uname=request.getParameter("user"); pwd=request.getParameter("pwd");

try

Class.forName("com.mysql.cj.jdbc.Driver");
String dbUrl = "jdbc:mysql://localhost:3306/mywebsite_db";

String dbUsername = "username";

String dbPassword = "password";

Connection con = DriverManager.getConnection(dbUrl, dbUsername, dbPassword);

Statement st=con.createStatement();

ResultSet rs=st.executeQuery("select name,password from personal where

name='"+uname+"' and password='"+pwd+"'"); if(rs.next())

out.println("Authorized person");

else

out.println("UnAuthorized person");
}

con.close();

catch(Exception e){out.println(""+e);}

%>

</body>

</html>
Output

Kashif Naseem 2201920130086

You might also like