Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In this lab you are going to implement basic login and logout operations using the Servlet Session Tracking API. 1 . Create a Java class

In this lab you are going to implement basic login and logout operations using the Servlet Session Tracking API.
1.Create a Java class User that represents a user. In particular, the User class should have at least three properties: name, username, and password. You may add additional properties like id if you want.
2. Create a servlet Login as follows:
(a) In the init() method of the Login servlet, create at least two User objects. One of the User objects must have the following property values:
name: "John Doe"
username: "jdoe"
password: "abcd"
Add the User objects to a list and save the list in application scope.
(b) In doGet(), display a login form, e.g.
Username:
Password:
Login (submit button)
The form should submit data to the Login servlet using a POST request.
(c) In doPost(), check if the submitted username and password match any user in the list of users. If a match is found (i.e. login is successful), set a session attribute user whose value is the User object that matches the submitted username and password, then redirect to the Members servlet. If no match is found (i.e. login fails), redirect back to the login form.
2.(20pt) Create a servlet Members. This servlet first checks if the session attribute user is set. If so, it displays the following:
Hi,! Welcome to the Members Area!
Logout
where is the name of the user who is currently logged in (you can get the name from the session attribute user which is a User object). If the session attribute user does not exist, the servlet redirects to the login form.
3.Clicking on Logout should take the user to a Logout servlet which invalidates the session (i.e. calling the invalidate() method in HttpSession), then redirects to the login form.
[Notes]
All Java classes in a web application must be in a package.
In Java, to check if the values of two strings are the same, you have to use the method equals() or equalsIgnoreCase() instead of the == operator.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Database And Knowledge Base Systems

Authors: S Krishna

1st Edition

9810206208, 978-9810206208

More Books

Students also viewed these Databases questions

Question

=+1. How does your message use verbal communication?

Answered: 1 week ago