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
when login is successful you can set a a value in session.setAttribute() and in all pages by using session.getAttribute() check if the value is present or not.If yes stay else go back to login page.
example
After login is successful do
session.setAttribute("user","user");
Now eac and every page check
if(session.getAttribute("user")==null)
{
response.sendRedirect("loginpage");
}
else
{
//your codes
}