Form-based authentication with a JDBC realm in GlassFish

Let's change basic authentication to form-based authentication, so that we can customize the login page. We need to update <login-config> in web.xml. Replace the previous <login-config> block with the following:

<login-config>    <auth-method>FORM</auth-method>    <realm-name>courseManagementJDBCRealm</realm-name>    <form-login-config>        <form-login-page>/login.jsp</form-login-page>        <form-error-page>/login-error.jsp</form-error-page>    </form-login-config></login-config>

We have replaced <auth-method> from BASIC to FORM. For form-based authentication, we need to specify form-login-page, which we have specified as login.jsp. form-error-page is optional, but we have set that to login-error.jsp.

Get Java EE 8 Development with Eclipse now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.