Question
Need help in implementing a basic login and logout operations using the Servlet Session Tracking API (NOT Cookies). In doPost(), check if the username and
Need help in implementing a basic login and logout operations using the Servlet Session Tracking API (NOT Cookies).
- In doPost(), check if the username and password match ericc and 123456, respectively. If the username and password are correct, set a session attribute user and redirect the user to the Members servlet; if not, redirect the user back to the login form. You may add additional accounts if you want, but ericc/123456 must be a valid account so we can test your code. Hints: You may store the pre-defined username and password information in servlet application scope and initialize the application scope in the init() method.
Note: Do NOT store the username and password in Cookies. If you do that, other people can easily get your username and password.
2. Create a servlet Members. This servlet first checks whether the session attribute user is set. If so, it displays the following:
Hi, ericc
Logout
Otherwise, it redirects the user back to the login form.
3.Clicking on Logout should take the user to a Logout servlet which invalidate the session (i.e. calling the invalidate() method in HttpSession), then redirect the user back to the login form.
In doGet(), display a login form, e.g. Username: Password: Login In doGet(), display a login form, e.g. Username: Password: Login
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started