There are a million examples on the web that shows how to create a basic Java Login Servlet, where the user has to enter a username and password which gets verified by some data
You can use a RequestFilter which will check for user session.
Read more : Filtering Requests and Responses