• Home
  • Docker
  • Kubernetes
  • LLMs
  • Java
  • Ubuntu
  • Maven
  • Big Data
  • Archived
Samples | FORM Authentication (Tomcat)
  1. The application structure
  2. Configure the file "tomcat-users.xml"
  3. Add and configure the file "web.xml"
  4. Add and configure the file "index.jsp"
  5. Add and configure the file "login.jsp"
  6. Add and configure the file "error.jsp"
  7. Test the FORM authentication

  1. The application structure
  2. Configure the file "tomcat-users.xml"
    You need to activate the users/roles that will be authorized to authenticate to the application.

    File location: ${TOMCAT_HOME}/conf/tomcat-users.xml

    Example:
  3. Add and configure the file "web.xml"
    You need to configure your application so it will handle FORM Authentication.

    File location: ${TOMCAT_HOME}/webapps/auth/WEB-INF/web.xml

  4. Add and configure the file "index.jsp"
    Here's a simple page that will show the connected user.

    File location: ${TOMCAT_HOME}/webapps/auth/jsp/index.jsp

  5. Add and configure the file "login.jsp"
    Here's a simple page that will allow the user to authenticate to the application.

    File location: ${TOMCAT_HOME}/webapps/auth/jsp/login.jsp

  6. Add and configure the file "error.jsp"
    Here's a simple page that will show an error message if the authentication failed.

    File location: ${TOMCAT_HOME}/webapps/auth/jsp/error.jsp

  7. Test the FORM authentication
    URL: http://localhost:8080/auth/jsp/

    tomcat-form-authentication

    Here are the requests headers as it will be send by the browser, and the responses headers as it will be send back by Tomcat:

    • First, the browser will send these headers as part of the request:
    • Second, Tomcat will send back these headers as part of the response (200 OK):
    • When you fill your username/password and you submit the form, the browser will send these headers as part of the request:
    • Then Tomcat will send back these headers as part of the response (200 OK + URL redirection):
    • Then the browser will send these headers as part of the request:
    • And then Tomcat will send back these headers as part of the response (200 OK):
© 2025  mtitek