Login Form & Registration Form with Database Project in JSP

Hi friends, in this tutorial I have given the clarity about login & registration form along with database in JSP in detail which will help you in project development.

Here I have considered MySQL as database environment. When the project will run, first a login form will display. Any new user(student) will enter into login form, if he/she will be a new user then he/she have do the signup first. Then click on signup link the user(student) will go to registration form.

In registration form the user(student) will give the detail and the data will go the database table then the user will do the registration successfully. Then from response page the user will come to again login form.

In registration form what ever the user will give the username and password value that values when the user will give in login form then he/she will go the home page.

The database table structure in MySQL environment is:

img
Required Files:

Login form : slogin.jsp
Registration form : sreg.jsp
Process file for registration form : sregprocess.jsp
welcome.jsp
Process file for login form : sloginprocess.jsp
shome.jsp
web.xml


The project Structure:
Projcet-structure

slogin.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Login Form</title>
    </head>
    <body>
        <center><h1>Student Login Form</h1>
            <form action="sloginprocess.jsp">
                <table>
                    <tr>
                        <td>UserName</td>
                        <td><input type="text"name="uname"></td>
                    </tr>
                    <tr>
                        <td>Password</td>
                        <td><input type="password"name="pass"></td>
                    </tr>
                    <tr>
                        <td><input type="submit"value="login"></td>
                        <td>Are you a new user, plz do<a href="sreg.jsp">signup</a> first</td>
                    </tr>
                </table>
            </form>
        </center>
    </body>
</html>

sreg.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Registration Form</title>
    </head>
    <body>
        <center><h1>Student Registration Form</h1>
            <form action="sregprocess.jsp">
                <table>
                    <tr>
                        <td>Regdno</td>
                        <td><input type="text"name="regdno"></td>
                    </tr>
                    <tr>
                        <td>Name</td>
                        <td><input type="text"name="name"></td>
                    </tr>
                    <tr>
                        <td>Semester</td>
                        <td><input type="text"name="semester"></td>
                    </tr>
                    <tr>
                        <td>Branch</td>
                        <td><input type="text"name="branch"></td>
                    </tr>
                    <tr>
                        <td>UserName</td>
                        <td><input type="text"name="uname"></td>
                    </tr>
                    <tr>
                        <td>Password</td>
                        <td><input type="password"name="pass"></td>
                    </tr>
                    <tr>
                        <td><input type="submit"value="signup"></td>
                    </tr>
                </table>
            </form>
        </center>
    </body>
</html>


sregprocess.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Insert title here</title>
    </head>
    <body>
        <%
            String s1=request.getParameter("regdno");
            String s2=request.getParameter("name");
            String s3=request.getParameter("semester");
            String s4=request.getParameter("branch");
            String s5=request.getParameter("uname");
            String s6=request.getParameter("pass");
            int k=0;
            try
            {
                Class.forName("com.mysql.jdbc.Driver");
                Connection

                con=DriverManager.getConnection("jdbc:mysql://localhost:3306/grievancedb","
                root","Silan@123");

                PreparedStatement ps=con.prepareStatement("insert into

                student_registration values(?,?,?,?,?,?)");

                ps.setString(1,s1);
                ps.setString(2,s2);
                ps.setString(3,s3);
                ps.setString(4,s4);
                ps.setString(5,s5);
                ps.setString(6,s6);
                k=ps.executeUpdate();
                if(k>0)
                {
                    response.sendRedirect("welcome.jsp");
                }
            }
            catch(Exception e)
            {
                e.printStackTrace();
            }
        %>
    </body>
</html>

sloginprocess.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Insert title here</title>
    </head>
    <body>
        <%
        String s1=request.getParameter("uname");
        String s2=request.getParameter("pass");
        try
        {
            Class.forName("com.mysql.jdbc.Driver");
            Connection

            con=DriverManager.getConnection("jdbc:mysql://localhost:3306/grievancedb","
            root","Silan@123");

            Statement statement=con.createStatement();
            ResultSet rs=statement.executeQuery("select * from
            student_registration where username='"+s1+"' and password='"+s2+"' ");

            if(rs.next())
            {
                response.sendRedirect("shome.jsp");
            }
        }
        catch(Exception e)
        {
            e.printStackTrace();
        }
        %>
    </body>
</html>

Output

student-login

student-registration

Then we will see database table(student_registration table of grievancedb database) by executing select * from grievancedb.student_registration

img

student-login-op

About the Author



Silan Software is one of the India's leading provider of offline & online training for Java, Python, AI (Machine Learning, Deep Learning), Data Science, Software Development & many more emerging Technologies.

We provide Academic Training || Industrial Training || Corporate Training || Internship || Java || Python || AI using Python || Data Science etc





 PreviousNext