Inside a filter I'm trying to send expired sessions back to a login page with a message that the user must login. I prefer to attach the message to the request object, rather than to the session object, so that I don't have to worry about erasing the message later.
When I use inside the filter:
catch (NullPointerException exc)
{
String message = "You must log in to access this site.";
url += "/login.jsp";
request.setAttribute("message", message);
httpResponse.sendRedirect(url);
}
The login page does NOT display the message (message is null). However, when I use:
session.setAttribute("message", message);
The message is displayed nicely on the login page.
In servlets, I have no problem attaching and displaying messages using the request object. It's only with filters that I'm noticing this difficulty.
Why is this happening, and can it be prevented? If I must use session when redirecting from a filter, what's the best way to erase the message on the JSP side?