Session timeout redirect
HDGeekAug 23 2012 — edited Aug 24 2012I am trying to redirect to another page when the session times out. I have put Frank's code in place (ApplicationSessionExpiryFilter) and when the session has expired and I click on a button on the page, I get a Message from webpage, "A connection to the server has failed. (status=404). I am running on my JDeveloper 11.1.2 Integrated Weblogic server.
This is not the expected behavior, and I have not been successful in troubleshooting this.
My web.xml code related to this:
<filter>
<filter-name>ApplicationSessionExpiryFilter</filter-name>
<filter-class>mypackage.util.ApplicationSessionExpiryFilter</filter-class>
<init-param>
<param-name>SessionTimeoutRedirect</param-name>
<param-value>/homePage.jsf</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>ApplicationSessionExpiryFilter</filter-name>
<servlet-name>Faces Servlet</servlet-name>
</filter-mapping>
<filter-mapping>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
<login-config>
<auth-method>BASIC</auth-method>
</login-config>
My ApplicationSessionExpiryFilter class code:
package mypackage.util;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class ApplicationSessionExpiryFilter implements Filter {
private FilterConfig _filterConfig = null;
public void init(FilterConfig filterConfig) throws ServletException {
_filterConfig = filterConfig;
}
public void destroy() {
_filterConfig = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
String requestedSession = ((HttpServletRequest)request).getRequestedSessionId();
String currentWebSession = ((HttpServletRequest)request).getSession().getId();
boolean sessionOk = currentWebSession.equalsIgnoreCase(requestedSession);
// if the requested session is null then this is the first application
// request and "false" is acceptable
if (!sessionOk && requestedSession != null){
// the session has expired or renewed. Redirect request
((HttpServletResponse) response).sendRedirect(_filterConfig.getInitParameter("SessionTimeoutRedirect"));
}
else{
chain.doFilter(request, response);
}
}
}
If you have any suggestions as to why this is not working, please advise. Thanks!