0

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 {

    }
user3235376
  • 87
  • 1
  • 2
  • 10

3 Answers3

1

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
}
Angelo Immediata
  • 6,635
  • 4
  • 33
  • 65
0

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:

Community
  • 1
  • 1
jmj
  • 237,923
  • 42
  • 401
  • 438
0

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 :)

Scott Shipp
  • 2,241
  • 1
  • 13
  • 20