0% found this document useful (0 votes)
8 views2 pages

Lab Assignment - 2

The document outlines a practical assignment for CSE 3rd Year students to create a JSP login page using a Type 1 JDBC driver. It includes steps to create a users table, configure ODBC DSN, and implement the login functionality with success or error messages based on user input. The JSP code provided connects to the database and verifies the username and password against stored records.

Uploaded by

suvadeeppal9
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)
8 views2 pages

Lab Assignment - 2

The document outlines a practical assignment for CSE 3rd Year students to create a JSP login page using a Type 1 JDBC driver. It includes steps to create a users table, configure ODBC DSN, and implement the login functionality with success or error messages based on user input. The JSP code provided connects to the database and verifies the username and password against stored records.

Uploaded by

suvadeeppal9
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

CSE 3rd Year 5th Sem, Sec- C & D (2025-26)

Lab/ Practical’s details:


1. Write a program in JSP to provide Login. Password Functionality using
Type 1 Driver.
Step 1: Create the users Table
CREATE TABLE users (
username VARCHAR(50) PRIMARY KEY,
password VARCHAR(50)
);
INSERT INTO users VALUES ('admin', 'admin123');
Step 2: Configure ODBC DSN
Step 3: JSP Login Page (login.jsp)
<%@ page import="java.sql.*" %>
<html>
<head><title>Login Page</title></head>
<body>
<h2>Login</h2>
<form method="post" action="login.jsp">
Username: <input type="text" name="username"><br><br>
Password: <input type="password" name="password"><br><br>
<input type="submit" value="Login">
</form>
<%
String uname = request.getParameter("username");
String pwd = request.getParameter("password");
if (uname != null && pwd != null) {
try { Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con =
DriverManager.getConnection("jdbc:odbc:UserDSN");
PreparedStatement ps = con.prepareStatement("SELECT * FROM users
WHERE username=? AND password=?");
ps.setString(1, uname);
ps.setString(2, pwd);
ResultSet rs = ps.executeQuery();
if (rs.next()) {
out.println("<h3 style='color:green;'>Login Successful! Welcome, " +
uname + ".</h3>");
} else {
out.println("<h3 style='color:red;'>Invalid username or
password.</h3>");
}
con.close();
} catch (Exception e) {
out.println("<h3 style='color:red;'>Error: " + e.getMessage() + "</h3>");
}}
%>
</body>
</html>
➢ The form submits to the same page (login.jsp).
➢ On submission, the JSP connects to the database using the Type 1 driver.
➢ It checks if the username and password match a record in the users table.
➢ Displays success or error message accordingly.
------------------------------------------------------------------------------------------------

You might also like