Sample code demonstrating how to use Form authentication using the JDBC Realm in Tomcat.
Steps explaining how this project was created and configured
- Use the tomcatAuth.sql script to create database and tables with sample data
- Create a dynamic Web project and select "Generate web.xml deployment descriptor" in the Web Module dialog
- Create an error.jsp, login.jsp and SecuredPage.jsp in the WebContent folder of your dynamic Web project
- Add the following form to the login.jsp page
-
Add the following code to your Dynamic Web Project Web.xml located in the WebContent-> WEB-INF folder My Secured Page /SecuredPage.jsp GET POST
admin
-
Make a backup copy of your server's server.xml file. Add the follwing code to your Server's server.xml file (if this code already exist in your server.xml you only need to modify the settings) in the "apache-tomcat-8.0.32 at localhost-config" folder of the Eclipse Servers folder. Change the user and password parameters to the values for you MySQL database
-
Copy the mysql-connector-java-5.1.37-bin.jar to your Apachie Tomcat lib folder
-
Deploy the application. Start the server and navigate to the following url to assess the application: http://localhost:8080/yourProjectNameGoesHere/SecuredPage.jsp
-
Test login by using the incorrect credentials to test that the error page displays
-
Test login using the correct credentials of tomcat for the username field and password for the password field