Develop form login pages

A Web client (browser) can authenticate a user to a Web server by using one of these mechanisms:

The HTTP Basic authentication transmits user password from the Web client to the Web server in simple Base64 encoding. Form based authentication transmits the user password from browser to Web server in plain text. Therefore, both HTTP Basic authentication and Form Based authentication are not very secure unless HTTPS is used.

The Web application deployment descriptor contains information about what authentication mechanism to use. When form-based authentication is used, the deployment descriptor also contains entries for login and error pages. A login page can be either a HTML page or a JSP page. This login page is displayed on the Web client when a secured resource (such as a servlet, JSP, or HTML page) is accessed from the application. If the authentication fails, the error page is displayed. You can write your own login and error pages to fit the needs of your application. During assembly of the application, an assembler can set the authentication mechanism for the application and set the login and error pages in the deployment descriptor.

Form login uses the servlet sendRedirect() method, which has several implications for the user. The sendRedirect() method is used twice during form login:

For more information and code examples, see Example: Form login.

  1. Create a form login page and the components to perform the form-based authentication.

  2. Create an error page. The error page can be programmed to retry authentication or display an error message that is appropriate.

  3. (Optional) Create a form logout page.

  4. Assemble the login, error, and logout pages in a WAR file. The pages should be placed relative to the root directory of the WAR file. For example, if the login page is configured as /login.html in the deployment descriptor, it is placed in the root directory of the WAR file.