Siksha Sarovar

Siksha Sarovar (sikshasarovar.com) is a free educational web application that helps students in India learn programming and prepare for academic and competitive exams. The platform offers structured coding courses (C, C++, Python, Java, HTML, CSS, PHP, Power BI, AI, Machine Learning, Data Science), complete university curriculum notes for BCA/MCA students with previous year question papers, Class 10 and Class 12 CBSE/HBSE school notes, and dedicated preparation material for SSC, UPSC, Banking, Railway and other government exams. Browsing the site is completely free and requires no account. Users may optionally sign in with Google solely to save their learning progress, quiz scores and personal preferences across devices.

Privacy Policy | Terms of Service | Contact Siksha Sarovar | About Siksha Sarovar

v4.0.9 · PWA
Siksha Sarovar logo
Siksha Sarovar
Your Learning Universe

Siksha Sarovar is a free e-learning platform for coding courses, BCA university notes and competitive exam preparation. Optional Google sign-in saves your learning progress across devices.

Initializing knowledge base…
Compiling modules 0%

Practical 11: JSP Registration & Login

Lesson 12 of 13 in the free Web Technology Lab (BCS552) notes on Siksha Sarovar, written by Rohit Jangra.

Program Statement

Write a JSP which inserts the details of 3 or 4 users who register with the website using a registration form. Authenticate the user when he submits the login form using the user name and password from the database.

The Real JSP + JDBC Code (Tomcat + MySQL)

<%-- register.jsp --%>
<%@ page import="java.sql.*" %>
<%
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    Connection con = DriverManager.getConnection(
        "jdbc:mysql://localhost:3306/webtechlab", "root", "password");
    PreparedStatement ps = con.prepareStatement(
        "INSERT INTO members (username, password) VALUES (?, ?)");
    ps.setString(1, username);
    ps.setString(2, password);
    ps.executeUpdate();
    con.close();
%>
<p>Registered successfully! <a href="login.jsp">Login now</a></p>
<%-- login.jsp --%>
<%@ page import="java.sql.*" %>
<%
    String username = request.getParameter("username");
    String password = request.getParameter("password");
    Connection con = DriverManager.getConnection(
        "jdbc:mysql://localhost:3306/webtechlab", "root", "password");
    PreparedStatement ps = con.prepareStatement(
        "SELECT * FROM members WHERE username = ? AND password = ?");
    ps.setString(1, username);
    ps.setString(2, password);
    ResultSet rs = ps.executeQuery();
    if (rs.next()) {
%>
        <p>Welcome, <%= username %>! Login successful.</p>
<%  } else { %>
        <p>Invalid username or password.</p>
<%  }
    con.close();
%>

Browser Simulation

The demo below mirrors both JSP pages: a Register form inserts {username, password} rows into localStorage (standing in for the members table), and a Login form runs the equivalent of SELECT ... WHERE username = ? AND password = ? against those stored rows.

CO Mapping

CO5