I think you’re looking for something like spring-security or app server proprietary ways of authenticating users stored in a database (like Tomcat’s JDBCRealm).
But frankly, if you know nothing about spring-security or even spring, and want to avoid proprietary solutions, writing your own servlet filter which goes to the database is quite an easy solution.
1
solved Java – log in, store users in database