Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361537
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:43:21+00:00 2026-06-09T11:43:21+00:00

In cases where the user has closed the browser and walked away, I want

  • 0

In cases where the user has closed the browser and walked away, I want to log when the session times out. For example as a system induced log out as opposed to user request (I already have working and tested code to log a user requested logout).

Since the user isn’t actively submitting requests (especially if it is just a matter of the now unused session timing out on the server) I don’t think a filter is possible. Can this be done with a phase listener? If so can you provide some insight or a skeleton, or at least point me in the right direction on how this might be done.

My understanding is that the session on the server is still active until it times out or some other mechanism invalidates it. I am assuming therefore that a phase listener will also be able to tell if as part of your login method, you kill any existing session prior to the user logging in again with a fresh view, other machine, etc.

I am OK with research, but would like to at least start while pointed in the right direction. 🙂

On a second note: Is it possible to differentiate between a session time out and a view expired?


Thought I’d post the solution I ended up with based on the suggestions:

public class ElsSoulardSessionListener implements HttpSessionListener {

    @EJB
    private SessionLogger sessionLogger = new SessionLogger();
    private SessionLogDTO sessionData = new SessionLogDTO();
    private ElsDateTimeFunctions ts = new ElsDateTimeFunctions();
    private static final Logger logger = Logger.getLogger(ElsSoulardSessionListener.class.getSimpleName());

    @Override
    public void sessionCreated(HttpSessionEvent se) {
        // Nothing to do yet
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent se) {
        logger.log(Level.FINE, "SESSION DESTROYED LISTENER");

        HttpSession session = se.getSession();
        finalizeUserSessionLog(session);
    }

    /**
     * Utility method to finalize user's session log entry. Returns 
     * early if the session log isn't found or more than one is returned.
     * @param session 
     */
    private void finalizeUserSessionLog(HttpSession session) {

        String sessionId = session.getId();
        LogoutReasonType logoutReason = (LogoutReasonType) session.getAttribute("logoutreason");

        if (logoutReason == null) {
            logoutReason = LogoutReasonType.SESSION_TIMEOUT;
        }

        try {
            sessionData = sessionLogger.findBySessionId(sessionId);
        } catch (NonexistentEntityException | UnexpectedResultSetSizeException ex) {
            logger.log(Level.WARNING, " sessionDestroyed ", ex);
            return;
        }

        Calendar now = ts.getUtcDateTimeAsCalendar();
        sessionData.setLogoutTimestamp(now);
        sessionData.setLogoutReason(logoutReason);
        sessionLogger.update(sessionData);

    }
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:43:22+00:00Added an answer on June 9, 2026 at 11:43 am

    If this helps you…

    In our application we have extended HttpSessionListener and used sessionDestroyed method to log the event of session timeout.

    and registered the same in web.xml as

    <listener>
        <listener-class>
            com.ourpackage.OurHttpSessionListener
        </listener-class>
    </listener>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a set of radio buttons. In some cases I want the user
We have a Silverlight application that runs OOB (out of browser) so the user
I have seen this question in SO several times. Most of cases user called
Given the use case where the user has to perform an online transaction, eg
I have a WPF System.Windows.Controls.WebBrowser control in a Window. A user can enter information
I'm saving the user language choice into the sessions like this: $this->session->set_userdata('language', $language); And
Use case: user clicks the link on a webpage - boom! load of files
In case user refuse to allow location update when on first time launch. how
If you set the Content-Disposition header to attachment , this causes user-agents to always
Here's the use case: A user clicks on a link that opens a window

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.