JSP Login and Logout System Example Using Session

In this tutorial you will learn how to make JSP login and logout system using session. I have used MySQL as a database in this example.

This system has following files.

index.jsp: It contains a login form which is displayed to user.

loginRequestHandler.jsp: When login form is submitted, this page handles the login request.

home.jsp: If the login details are correct then the user will be redirect to home page. It contain welcome message with a logout link.

logout.jsp: It invalidates the session and logout the user from system.

DBConnection.java: It handles connectivity with the database.

LoginBean.java: It is a bean class that has getter and setter methods.

LoginDAO.java: This class verifies the email and password from the database.

 

The database table that I have used has following structure.

Login Table

 

I have done proper session tracking in this example. If the user is not logged in and tries to open home.jsp page then he/she will be redirected to index.jsp page for login. If he/she is already logged in and tries to open index.jsp then he/she will be directly redirected to home.jsp.

Below I have shared the code for each of these files.

 

index.jsp

 

loginRequestHandler.jsp

 

home.jsp

 

logout.jsp

 

DBConnection.java

 

LoginBean.java

 

LoginDAO.java

 

Screenshots

Index Page

Home Page

Comment below if you are facing difficulty to understand anything in above JSP login and logout system.

Happy Coding!! 🙂 🙂

 

14 thoughts on “JSP Login and Logout System Example Using Session”

  1. Loved The Clarity in the Code !!. Can you please share a spring based program too. I have mentioned my email address below.

    Thanks

  2. Thank you very much. Can you please help me to create log in form and a form generating a data value from my excel file.

  3. greate!!!!!! but when i am clicking on back button it is going to home.
    it is not secure.
    please help me when i click on back button control must stay on index page after logout.

  4. Hi, I have written same code in eclipse IDE and i am getting false value from LoginDao.java. I think something is wrong with the data in DB.

    created table is:
    create table emp(“name” varchar2(4000),
    “email” varchar2(4000),
    “pass” varchar2(4000));

    select * from emp ;

    and values are:
    iyanka [email protected] 12376sga45
    Priyanka [email protected] 12345

    but when i am giving [email protected] as email and 12345 as password it is giving me false value.
    Could you please help me here!!??

  5. Very Very Thanks to you I searched many website simplicity and understandable code find on your codes
    once again thank you very much

  6. I didn’t understand why you use
    ps.setString(1,loginBean.getEmail());
    ps.setString(2,loginBean.getPassword());
    Since setString is used to store data in DataBase and here we only retrieving and comparing .

  7. Sir im totally Confused About the HIBERNATE framework.Hibernate While sending data into Database or with the data sends the Image too. please share Some Tutorials on my Email:- [email protected]

Leave a Comment

Your email address will not be published. Required fields are marked *