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 {

    }

3 Answers 3

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
}
Sign up to request clarification or add additional context in comments.

Comments

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:

Comments

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.