Hi everyone. I am trying to understand how
servlet filters work by using the "tutorial" given at
this blog
Project-
I won't paste the full code, but I will only focus on the main logic of the code in the project. I have posted the web.xml though.
web.xml-
1) login.html - You will be asked to enter user and password here. Only user = user, password = pass is correct. This page directs you to LoginServlet.
2) LoginServlet.java - If your user and pass is correct, then a cookie for user= "user", is set for 30 minutes and you are directed to LoginSuccess.jsp.
Otherwise, you are directed to the login.html of (1).
3) LoginSuccess.jsp - If username of cookie set by LoginServlet not null, that is user is NOT active, then direct to login.html of (1). Alternately, let the user
click logout button and go to the LogoutServlet.java.
4) LogoutServlet.java - If the user in cookie is "user", then "kill" the cookie and send the user back to login.html of (1)
Now, when I run this code and I enter the right user/password, I am redirected to the login.html page. This happens because of the logic inside AuthenticationFilter.
I was expecting to go to the LoginSuccess servlet instead.
Why would someone want to have this seemingly counter intuitive logic ?
Also, when I remove the mappings for the filters (below) from web.xml, the code works as expected.