Hello everybody!
There is a project I developed quite some time ago - Simple Servlet Login Logout Example Using Cookies. Using some controls, I checked if the user logged in before reaching a certain page. There is no database connection in this project so do not keep your hopes too high :D I will only share basic points about cookies in the project. Because the rest is not a big deal. You can benefit more from my other project explanation posts if you are interested in the rest.
|
index.html |
|
login.html |
This is the index.html page. As you can see there is a login button. Clicking the login button, the user will be asked to enter "name" and "password" information. Our job is to take these information, process them by checking if they match what we are looking for and if everything is OK, create a cookie to store these information. Cookies are kept in the client side and they have expiration time. The code which is responsible for all these features in LoginServlet. So if you want to see what is in LoginServlet, you can check below.
|
LoginServlet |
There is also profile page link in the index.html page. Clicking this, "ProfileServlet" will be used. You can see it below.
|
ProfileServlet |
Last but definitely not the least, "Logout" link will invoke "LogoutServlet" which will delete the cookie as stated below.
|
LogoutServlet |
I will not be showing any web.xml configuration as I already did a couple of times before. I also have a similar login logout project by using sessions. You can view it
here.
Hope to see you in the next blog post!
Selen
WOO
ReplyDelete