trainingtrains Logo

91-9990449935

 0120-4256464

Servlet Login and Logout Example using Cookies

A cookie is a kind of information that is stored at client side.

In the previous page, we learned a lot about cookie e.g. how to create cookie, how to delete cookie, how to get cookie etc.

Here, we are going to create a login and logout example using servlet cookies.

In this example, we are creating 3 links: login, logout and profile. User can't go to profile page until he/she is logged in. If user is logged out, he need to login again to visit profile.

In this application, we have created following files.

  1. index.html
  2. link.html
  3. login.html
  4. LoginServlet.java
  5. LogoutServlet.java
  6. ProfileServlet.java
  7. web.xml
File: index.html

File: link.html

File: login.html

File: LoginServlet.java

File: LogoutServlet.java

File: ProfileServlet.java

File: web.xml

Output

servlet cookie login example 1 servlet cookie login example 2 servlet cookie login example 3 servlet cookie login example 4 servlet cookie login example 5 servlet cookie login example 6

If again you click on the profile link, you need to login first.