Reputation: 87
I need to write a code, that will be redirecting to different *.jsp sites depending on whether user is logged on or not logged on. I found a hint, that I can use filter to do it and I need to use doFilter or/along with init methods. Any ideas?
public void doFilter(ServletRequest req, ServletResponse res,
FilterChain chain) throws IOException, ServletException {
}
public void init(FilterConfig config) throws ServletException {
}
Upvotes: 0
Views: 163
Reputation: 6944
This is a very basic sample...but let's suppose that the login proces set in session an attribute called "user" in the doFilter method you can do something like this
if( request.getSession().getAttribute("user") == null )
{
//User not logged...redirect
}
else
{
//Normal filter execution
}
Upvotes: 1
Reputation: 2301
For an example, see Filters Tutorial, particularly the section titled Authentication with Filters. (There's a typo that actually makes this say "Authentication with Filers" but that is the section I am referring to...obviously it is supposed to say filters :)
Upvotes: 0
Reputation: 240860
init()
method will be called on Filter's initialization and doFilter()
will be called when a request is made and Filter
is mapped to filter those request
Related:
Upvotes: 0