Posted by: techiexchange on: February 21, 2008
With JSF, a clean Session expiry or timeout is not easy to implement. So, I would like to post a solution that you can integrate it as out-of-box with your JSF applications.
Here is a better version of code with syntax highlight:
http://techieexchange.blogspot.com/2008/02/jsf-session-expiry-timeout-solution.html
public class MySessionListener implements HttpSessionListener {
HttpSession session = event.getSession(); System.out.println(“Current Session destroyed :” + session.getId() + ” Logging out user…”); /* * nobody can reach user data after this point because session is invalidated already. * So, get the user data from session and save its logout information * before losing it. * User’s redirection to the timeout page will be handled by the SessionTimeoutFilter. */
// Only if needed
* Clean your logout operations.
*/
public void prepareLogoutInfoAndLogoutActiveUser(HttpSession httpSession) {
*When the session destroyed, MySessionListener will do necessary logout operations.
public class SessionTimeoutFilter implements Filter {
if (isSessionControlRequiredForThisResource(httpServletRequest)) { // is session invalid?
if (isSessionInvalid(httpServletRequest)) {
* Since we’re redirecting to timeout page from this filter,
Web.xml<listener>
<listener-class>
com.fpc.carconfig.session.MySessionListener
</listener-class>
</listener>
<filter>
<filter-name>SessionTimeoutFilter</filter-name>
<filter-class>
</session-config>
Feel free to share your comments.
Great Article! I have a question though.
Is there any chance that once the timeout expires, the application redirects the user to the timeout page without waiting for the user to make another move?
Thanks!
I tested with that, it run fine, but there is a problem.
It run twice, anyone have had the same problem same me
StringUtils() not workig for me… i am using ibm/rad
i went url which u posted to get it done….
but can you tel me wat and where i download sources or binary and all those and how do i integrate to my IDE…
should i use or integrate jars like thing(adding Externa jars)
help me
thanks
For some reason, I don’t see control going in to Filter any time even after giving a URL pattern of *.*
Is there any thing I am missing?
I am using Struts and I see the control going in to init() method of Filter but it never got in to doFilter() method. Can someone help me?
Nice solution, but how to use the resource bundle inside the SessionTimeoutFilter
I am having in login page
and adding error message as follows in the backing bean.
————————————————————————————
FacesContext facesContext = FacesContext.getCurrentInstance();
FacesMessage message = new FacesMessage(severity, summary, detail);
facesContext.addMessage(clientId, message);
————————————————————————————
The error is NullPointerException, while adding messages.
March 6, 2008 at 8:46 am
Hi, thank you very much for you article!
But happen question.
Please cane you add StringUtils class to this article because in
antlr.StringUtils i no found contains() method and
please can you describe isSessionControlRequiredForThisResource() more detail