|
RHS |
You are to make a simple login form (username + password) and a Servlet that checks if the username and password are OK.
Don't worry about the visual design of the page.
The password field is of
type password - that's why you see the stars in the input field in the
browser.
The action attribute of the form should refer to a page called checklogin.
The method attribute of the form must be post.
Make a Servlet using Netbeans:
This Servlet is supposed to check the validity of the username and password from the login form.
Things can go wrong in many ways:
|
If username and password is accepted the user should see a HTML-page with a greeting!
In the login form page change the method attribute from post to get.
What effects does this have when you re-run the web application?
Do you prefer GET or POST?
As you can see from the above screen shots the title of the Servlet generated pages are "Servlet checklogin".
Change the Servlet to generate a more appropriate title.
This is an extra exercise for those of you who finished the above exercises quickly: The fast and the fearless!
In case of bad username or password the Servlet should forward the request back to the login form.
Make another NetBeans project.
Technical hint:
getServletContext().getRequestDispatcher("/login.jsp?message=No username").forward(request, response);
forward the request. More information in Marty Hall: Core Servlets and JavaServer Pages, page 223-224.
Note that the Servlet is not allowed to do send any output to the client (browser) prior to forwarding.
Note that the login form page is now a JSP page, not an HTML page. This allows is to show an optional message to the user.