Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create a web application called MyLogin . Add two servlets to this application. LoginServlet : Handles all authentication and creation/destruction of sessions. doGet() displays a

Create a web application called MyLogin. Add two servlets to this application.

  1. LoginServlet: Handles all authentication and creation/destruction of sessions.

doGet() displays a login form (login.jsp) to the user that can also show messages.

doGet() is also responsible for logging out the user. If the parameter logout exists, invalidate the session and display a message that the user has successfully logged out.

doPost() processes the submission of the form from login.jsp. doPost() first validates that user name and password are not empty. Then, it passes the user name and password parameters to the login() method of a service class called AccountService. If login() returns a non-null value, store the username in a session variable and redirect (not forward) the user to the home url. If the authentication parameters are invalid, display an appropriate error message, keeping the textboxes filled in with what the user had previously entered and forward the user to login.jsp.The URL for LoginServlet is /login

  1. HomeServlet: shows a welcome message (home.jsp) to the user including their username. The JSP home.jsp also shows a Logout hyperlink which makes a get request to take the user back to URL login and displays the message You have successfully logged out.

The url of HomeServlet is /home

The AccountService class is very simple. It has only one (non-static) method:

public User login(String username, String password)

which validates the user and password. If the login is successful, return a user object, with the password set as null. If the login is not successful, return null.

There are two user names should validate successfully: adam and betty. Both users have a password of password. Any other login data should not be accepted. You can hard code adam and betty in the AccountService class.

Handle all unexpected errors appropriately. E.g. 404 file not found, or thrown exceptions.

The welcome page should be set to /home. If an authenticated user returns to our website, we want to give them the /home page not /login. If the user attempts to access /login and the session object username exists, redirect them to /home. If the user attempts to access /home directly and the session object username does not exist, redirect them to /login.

image text in transcribed

Example 1: /login initial view (when application is run) Login Username: Password: Log in Example 2: /home when adam has logged in successfully Home Page Hello adam. Log out Example 1: /login initial view (when application is run) Login Username: Password: Log in Example 2: /home when adam has logged in successfully Home Page Hello adam. Log out

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

Larry Ellison Database Genius Of Oracle

Authors: Craig Peters

1st Edition

0766019748, 978-0766019744

More Books

Students also viewed these Databases questions