How to perform authentication. If the user is not logged in it should redirect to login page if the user is already logged in it should redirected to homepage. How can i do this with servlets ?
Asked
Active
Viewed 372 times
1 Answers
0
You can write servlet filter which intercepts all the requests coming to you application and check if user is logged in or not by checking attributes stored in session. To know how to create filter follow this link.
If you are using another servlet to authenticate the user You can if necessary specify the paths-to-be-ignored as an init-param of the filter so that you can control it in the web.xml anyway. You can get it in the filter as follow
private String pathToBeIgnored;
public void init(FilterConfig config) {
pathToBeIgnored = config.getInitParameter("pathToBeIgnored");
}

hiren
- 1,742
- 13
- 20