When a session is destroyed

I am trying to use SessionListener Class. When I open the site the method "sessionCreated" is called. But when I close the window it seems that "sessionDestroyed" is not called.
I am confused that when actually a sesion is destroyed.

Hi!
When U close the browser-window on the client-side, nothing happens to the session on the server side.
There are 2 situations when a session is destroyed:
- a session may have a time out, that means after a specified time of inactivity from the client the server destroys the session (this will happen when U close the browser-window. Not at the moment of closing but from then on there will be no more activity and then the time will run down. This time can be set within the deployment-descriptor (web.xml) for example.
- you call the method session.invalidate(). (This is what the server does when session times out too). Maybe this is done in a logout-servlet or alike.
Hope this answers your question.
Thomas.

Similar Messages

  • JSP session getting destroyed when second user logs in

    Hi,
    I am facing a session related problem in a small login program in jsp. I am using three jsp pages, login.jsp (user logs in), page1.jsp (creates a session and stores username) and page2.jsp (accesses session).
    Login.jsp:
    No jsp actually. Just a simple html form.
    Page1.jsp:
    String name=request.getParameter("Name");
    session=request.getSession(true);
    session.setAttribute("Name",name);
    Page2.jsp:
    session=request.getSession(false);
    if(session.isNew())
    System.out.println("new session created");
    String name=session.getAttribute("Name").toString();
    As expected, it works like session getting set at page1 and used at page2. It works good if users log in one by one. The problem arises when 2 (or more users with different logins) try to access the page at same time. When a new user logs in, the previous user session gets destroyed (session.isNew() becomes true and session Id changes).
    Is it the way I am using sessions (missing something), or there is some setting in tomcat server to specify maximum number of logins (sessions that can be handled).
    Regards
    Kamal

    Hi,
    Thanks for reply, but I guess the problem is not clear. Let me explain..
    A user logs in, he reaches first page (page1.jsp), here session is getting set. Then user goes to page2.jsp where application retrieves the information from session and uses it. It works all well.
    When two (or more) user logs in.. First user logs in, he reaches page 1, session is set. But then another user logs in (different id) and a session is set for him as well. Now the problem here is that session for first user gets destroyed at this point, which is unexpected (two sessions should not conflict, on different machines).
    Additionally, the problem does not happen necessarily at second login. eg. sometimes 4 users log in and when fifth one logs in, fourth gets logged out (session gets destroyed).
    I am not able to figure out, whether the problem is in code (given in first post) or there is some tomcat setting responsible for this behavior.
    Regards
    Kamal

  • Ensuring items are removed when session is destroyed

    I have a Spring 2.5 MVC application with the ACEGI security framework on top of that. This application allows the user to upload many files and then "publish" them as a whole. I need to ensure that these files are deleted if the following happens:
    1. The user clicks cancel (done, processCancel)
    2. The session expires (trying HttpSessionListener)
    3. The user navigates away from the page (This can probably fall under session expiration)
    4. The user closes the browser(This can probably fall under session expiration)
    Currently I implement the HttpSessionListener. I am not getting the same ID on sessionDetroyed that I am getting on sessionCreated. I'm assuming either the session is already destroyed before that event fires. Also, the sessionDestroyed event does not fire when I close the Firefox browser, but it does when I close Internet Explorer.
    I was thinking that I can put a static reference to a map of files that need deleted on session expiration in the listener, but I'm still not sure how to link the session ID to the files or the username of the currently logged in user. Basically I need to verify that the files I am deleting do not belong to a user who is still logged in. Is there a better way to do this?

    hoffmandirt wrote:
    Currently I implement the HttpSessionListener. I am not getting the same ID on sessionDetroyed that I am getting on sessionCreated. I'm assuming either the session is already destroyed before that event fires. The sessionDestroyed event occurs after the session is taken out of commission but before it is invalidated. Every session gets destroyed and will have this sessionDestroyed event called. If you are using sessionEvent.getSession().getID() that will be the ID of the session about to be invalidated. It is hard to say why you are getting different sessions, but my guess is that you get the sessionID early in your app and somewhere you force a new session to be created and you are mixing the two sessions here. Some code may help figure this out. The second session would eventually expire, though, after the session timeout occurs.
    Also, the sessionDestroyed event does not fire when I close the Firefox browser, but it does when I close Internet Explorer.Sessions are not destroyed when a browser closes. They are destroyed when you explicitly call a session.invalidate() or when the session times out. If you waited whatever period of time your session is set to timeout after you close the browser, that is when the sessionDestroyed method would be called.
    >
    I was thinking that I can put a static reference to a map of files that need deleted on session expiration in the listener, but I'm still not sure how to link the session ID to the files or the username of the currently logged in user. Basically I need to verify that the files I am deleting do not belong to a user who is still logged in. Is there a better way to do this?I personally don't like the static resource thing. It gets confusing when you start to worry about class loaders and is too easy to flub. Better would be a map stored in the application context that both your main application has access to and the HttpSessionListener (via the HttpSession object) has access to. But I would also think about wrapping the references to the file in a 'SessionFile' object which would implement HttpSessionBindingListener and would delete itself when the valueUnbound event occurs. So the file would be deleted when the session ends as well as when you simply delete it from the session. No need for an external map in the context/static scope, or an HttpSessionListener running in the background.
    public class SessionFile implements HttpBindingListener {
        private final File file;
        private boolean fileInSession = false;
        public SessionFile(File file) { this.file = file; }
        public File getFile() {
            if (!fileInSession) {
                throw new IllegalStateException("Can not access File.  It is no longer stored in session.");
            return this.file; }
        public void valueBound(HttpSessionBindingEvent event) {
            this.fileInSession = true;
            /* any special action when added to the session? */
        public void valueUnbound(HttpSessionBindingEvent event) {
            this.fileInSession = false;
            // delete the file here
    }

  • Session not destroyed after restart

    Hi all,
    On my Application server 8.1_02 EE as well as 8.2 PE i have an application.
    The session is destroyed on log out... but after a successful restart of the application server, the session is kept active..
    Is this a normal behavior, or is there something that i must be aware of?
    Thanks,
    Scotty

    Hi Ronald,
      I once encountered a similar problem when calling a BSP application in a GUI HTML control. I used a copy of session_single_frame in my BSP application and it worked fine when I called the BSP application from SE80 or by entering the URL in the browser directly but I couldn' t get it to work in the HTML control.
    The solution then was to use an additional URL Parameter called sap-syscmd=NOCOOKIE. This tells the request handler on the Web AS to retrieve the session ID from the URL and not to use a cookie.
    Hope this helps,
    Andy

  • Redirect to main jsp when the session expires

    Hi,
    I have a jsp say mainframe.jsp in which I have two frames each having a jsp page say child1.jsp and child2.jsp.
    When the session expires and I when i try do any changes in child2.jsp or child1.jsp, the page redirects to login page and when I login successfully, I am getting redirected to child2.jsp or child1.jsp respectively. But I want it to be redirected to mainframe.jsp.
    Any help is greatly appriciated.
    Thanks in advance.
    Vinod

    I think I am not clear.
    When I try to login after session expiry, I am redirected to child jsp.
    But what I want is that I should be redirected to mainfram.jsp page.
    url in the address shows : ../mainframe.jsp?ID=******
    When my seesion is expired and I try do some manipulation in child1.jsp (which is inside a frame of my mainframe.jsp). it is redirected to login page and from there to child1.jsp instead of mainframe.jsp
    Now the address url shows : ../child1.jsp?ID=********* because of which I am not able to see child2.jsp along with child1.jsp
    What I want : ../mainframe.jsp?ID=********
    this is the code I am using !!
    String destPage = request.getRequestURI();
    response.sendRedirect("../redirect.jsp?dest=" + URLEncoder.encode(destPage));

  • Error when Create Session Bean in JDeveloper

    Hi All,
    I followed the steps in the SRDemo tutorial to create Session bean SRPublicFacade. I used Create Session Bean wizard. Step 1 was ok. Step 2 when it's supposed to show all the POJOs and all methods (from Queries) it hang there, and skipped to Step 3 and so on... As a result I had an empty Session Bean with only class name and no methods in it. I do have correct database connection, and I have another project with similar Session Bean sucessfully. I just don't know what happened to this project or the way I created session bean this time. Any conflict when create Session Bean to the same database or something(?) Anyone has any idea please let me know.
    Thank you very much,
    John

    Frank,
    Yes, I compiled the project before building the session facade. I used JDeveloper 10.1.3.3.0
    The thing is I once created successfully the session facade in another project, like SRdemo. Now I would like to repeat that in another project say SRdemo2, then it went wrong. It skipped step 2 in the wizard and look like it cannot detect the tables and named queries.
    Thanks,
    John

  • How do I close a connection when the session ends?

    I have a website that is using JavaMail to display a user's mail through the browser. I'd like to keep the connection to the mail server open during the whole session that the user is logged in, in order to improve response time. The problem is, I can't detect if a user closes their browser so that I can close the connection to the server.
    Is there a way for me to close the mail server connection when the session ends?
    Thanks.

    Create session listener, Impliment sessionDestryoyed
    method with your connection close statements.I was wondering how to use the listener for a Servlet as well, what would you type in that method to close the connection?.
    public class ServletListener
         implements
              ServletContextListener,
              ServletContextAttributeListener,
              HttpSessionListener,
              HttpSessionAttributeListener
    public void sessionDestroyed(HttpSessionEvent arg0)
              //System.out.println( arg0 );
    }

  • Delete memory Id when the session is still active

    Hi all,
    Can anyone tell me how to clear the Memory Id when the session is still active.
    I am getting the amount value through Memory Id from import and export parameter when I am posting the check. Again if I reprint the check without closing the session the amount value is getting double evertimes.
    If I delete from Memory Id I am not able to see any amount value while posting for first time.
    Can anyone suggest me how to proceed further.
    Regards
    Yathish

    Looks like you are not clearing the variables before and after that logic. Clear them and try.
    Let us if you are doing that or not.
    Rgds,
    Naren
    Message was edited by:
            Someneni

  • [svn] 2692: Bug: BLZ-227 - When using JMS Destination, MessageClient and FlexClient not released from memory when the session times out .

    Revision: 2692
    Author: [email protected]
    Date: 2008-07-31 13:05:35 -0700 (Thu, 31 Jul 2008)
    Log Message:
    Bug: BLZ-227 - When using JMS Destination, MessageClient and FlexClient not released from memory when the session times out.
    QA: Yes
    Doc: No
    Checkintests: Pass
    Details: Fixed a memory leak with JMS adapter. Also a minor tweak to QA build file to not to start the server if the server is already running.
    Ticket Links:
    http://bugs.adobe.com/jira/browse/BLZ-227
    Modified Paths:
    blazeds/branches/3.0.x/modules/core/src/java/flex/messaging/services/messaging/adapters/J MSAdapter.java
    blazeds/branches/3.0.x/qa/build.xml

    Revision: 2692
    Author: [email protected]
    Date: 2008-07-31 13:05:35 -0700 (Thu, 31 Jul 2008)
    Log Message:
    Bug: BLZ-227 - When using JMS Destination, MessageClient and FlexClient not released from memory when the session times out.
    QA: Yes
    Doc: No
    Checkintests: Pass
    Details: Fixed a memory leak with JMS adapter. Also a minor tweak to QA build file to not to start the server if the server is already running.
    Ticket Links:
    http://bugs.adobe.com/jira/browse/BLZ-227
    Modified Paths:
    blazeds/branches/3.0.x/modules/core/src/java/flex/messaging/services/messaging/adapters/J MSAdapter.java
    blazeds/branches/3.0.x/qa/build.xml

  • How to make the changes to be permanent when a session is executed successfully ?

    Hi Everyone,
    I am new to ODI.
    I am learning how to create interfaces for the data flow between two Oracle databases !
    Now I started by developing a simple interface of loading data from EMPLOYEES table of HR schema to another table created by me EMPLOYEES_TGT in the same schema.
    When I dragged and dropped the source and target tables in the mapping tab it showed do you want to map automatically. I selected Yes and then When i executed the project I got errors and I have manually changed the code in the session. One session is executed correctly after changing the code in the sessions, when I start the same project once again it is throwing the same errors. How can I make the changes of the code that I changed in the previous session permanent to that interface ?
    Could anyone please guide me how to overcome this problem ? How can i make the changes permanent when one session has completed execution ?
    Thanks& Regards,
    Anvesh

    Hi Raghunar,
    The following is the code generated by default with the interface:
    insert /*+ append */ into HR.I$_EMPLOYEES_TGT
      EMPLOYEE_ID,
      FIRST_NAME,
      LAST_NAME,
      EMAIL,
      PHONE_NUMBER,
      HIRE_DATE,
      JOB_ID,
      SALARY,
      COMMISSION_PCT,
      MANAGER_ID,
      DEPARTMENT_ID,
      IND_UPDATE
    select
    EMPLOYEE_ID,
      FIRST_NAME,
      LAST_NAME,
      EMAIL,
      PHONE_NUMBER,
      HIRE_DATE,
      JOB_ID,
      SALARY,
      COMMISSION_PCT,
      MANAGER_ID,
      DEPARTMENT_ID,
      IND_UPDATE
    from (
    select 
      EMPLOYEES.EMPLOYEE_ID EMPLOYEE_ID,
      EMPLOYEES.FIRST_NAME FIRST_NAME,
      EMPLOYEES.LAST_NAME LAST_NAME,
      EMPLOYEES.EMAIL EMAIL,
      EMPLOYEES.PHONE_NUMBER PHONE_NUMBER,
      EMPLOYEES.HIRE_DATE HIRE_DATE,
      EMPLOYEES.JOB_ID JOB_ID,
      EMPLOYEES.SALARY SALARY,
      EMPLOYEES.COMMISSION_PCT COMMISSION_PCT,
      EMPLOYEES.MANAGER_ID MANAGER_ID,
      EMPLOYEES.DEPARTMENT_ID DEPARTMENT_ID,
      'I' IND_UPDATE
    from HR.EMPLOYEES   EMPLOYEES
    where (1=1)
    ) S
    where NOT EXISTS
      ( select 1 from HR.EMPLOYEES_TGT T
      where 
      and ((T.EMPLOYEE_ID = S.EMPLOYEE_ID) or (T.EMPLOYEE_ID IS NULL and S.EMPLOYEE_ID IS NULL)) and
      ((T.FIRST_NAME = S.FIRST_NAME) or (T.FIRST_NAME IS NULL and S.FIRST_NAME IS NULL)) and
      ((T.LAST_NAME = S.LAST_NAME) or (T.LAST_NAME IS NULL and S.LAST_NAME IS NULL)) and
      ((T.EMAIL = S.EMAIL) or (T.EMAIL IS NULL and S.EMAIL IS NULL)) and
      ((T.PHONE_NUMBER = S.PHONE_NUMBER) or (T.PHONE_NUMBER IS NULL and S.PHONE_NUMBER IS NULL)) and
      ((T.HIRE_DATE = S.HIRE_DATE) or (T.HIRE_DATE IS NULL and S.HIRE_DATE IS NULL)) and
      ((T.JOB_ID = S.JOB_ID) or (T.JOB_ID IS NULL and S.JOB_ID IS NULL)) and
      ((T.SALARY = S.SALARY) or (T.SALARY IS NULL and S.SALARY IS NULL)) and
      ((T.COMMISSION_PCT = S.COMMISSION_PCT) or (T.COMMISSION_PCT IS NULL and S.COMMISSION_PCT IS NULL)) and
      ((T.MANAGER_ID = S.MANAGER_ID) or (T.MANAGER_ID IS NULL and S.MANAGER_ID IS NULL)) and
      ((T.DEPARTMENT_ID = S.DEPARTMENT_ID) or (T.DEPARTMENT_ID IS NULL and S.DEPARTMENT_ID IS NULL))
    I modified the code to the following :
    insert /*+ append */ into HR.I$_EMPLOYEES_TGT
      EMPLOYEE_ID,
      FIRST_NAME,
      LAST_NAME,
      EMAIL,
      PHONE_NUMBER,
      HIRE_DATE,
      JOB_ID,
      SALARY,
      COMMISSION_PCT,
      MANAGER_ID,
      DEPARTMENT_ID,
      IND_UPDATE
    select
    EMPLOYEE_ID,
      FIRST_NAME,
      LAST_NAME,
      EMAIL,
      PHONE_NUMBER,
      HIRE_DATE,
      JOB_ID,
      SALARY,
      COMMISSION_PCT,
      MANAGER_ID,
      DEPARTMENT_ID,
      IND_UPDATE
    from (
    select 
      EMPLOYEES.EMPLOYEE_ID EMPLOYEE_ID,
      EMPLOYEES.FIRST_NAME FIRST_NAME,
      EMPLOYEES.LAST_NAME LAST_NAME,
      EMPLOYEES.EMAIL EMAIL,
      EMPLOYEES.PHONE_NUMBER PHONE_NUMBER,
      EMPLOYEES.HIRE_DATE HIRE_DATE,
      EMPLOYEES.JOB_ID JOB_ID,
      EMPLOYEES.SALARY SALARY,
      EMPLOYEES.COMMISSION_PCT COMMISSION_PCT,
      EMPLOYEES.MANAGER_ID MANAGER_ID,
      EMPLOYEES.DEPARTMENT_ID DEPARTMENT_ID,
      'I' IND_UPDATE
    from HR.EMPLOYEES   EMPLOYEES
    where (1=1)
    In the same way for other steps in the same session I got some errors and I fixed them by changing the code. But the problem is that where can I change this so that it will be a permanent solution.
    Thanks,
    Anvesh

  • How to know when a session has gone by closing browser or leaving site.

    Hi! I'm doing an application that uses the session API. This application must run in every java-enabled web-server. I want to know if there is a way to know when a session has gone. I mean, you can know this if, for example, you call the isNew method. But for example, if you close the browser, the session is gone, but obviously, I can't call the isNew method from anywhere, so... how can I know when the session is killed by closing de browser or if the user leaves the site. You can use the onUnload of JavaScript, but I don't want to call a new window when this happens.
    Hope you can help me!

    You probably can't tell. But then you don't want to do that logic anyway... I was just at your site, and I was signed on, then somebody came in and asked me something so I had to look at another site, then I pressed the back button and now I'm at your site again, but you signed me out? What's with that?

  • Custom web parts in SharePoint 2013 becomes inactive when the session is idle for long time.

    Hi,
    We have a search center site with custom web parts and custom master pages. When the session is inactive for long time all the custom web parts in the page doesn't work, unless we close the browser and open it. Where as this is not the case with the
    OOB web parts. We are not able to identify the root cause as it works with OOB web parts and not the custom web parts.We were able to find that by increasing the session timeout of the web application we can avoid this issue.We do not want to increase the
    session timeout as the OOB web part works perfectly even when the user session is idle for long time.Is there any other alternative where we can acheive the same for custom web parts when the session is idle for long time?
    Thanks,
    Saranya

    Hi Saranya,
    According to your descirption, my understanding is that when the session is long time idle ,then custom web part will not work.
    I suggest you check if you have enable the session in the Page Level in the web.config. By default SharePoint disable the session state.
    In the web.config, you will see <page enableSessionState> tag. You can modify like below and test if it works.
    <pages enableSessionState=”true” ….. />
    Here is a detailed thread for your reference:
    Use Session State in SharePoint
    Best Regards
    Zhengyu Guo
    TechNet Community Support

  • ORA-12721: operation cannot execute when other sessions are active

    Hi,
    I started my DB like following :
    1) Change INIT.ORA file;  unset parallel_server parameter.
    2) Execute these commands:
    STARTUP MOUNT ;
    ALTER SYSTEM ENABLE RESTRICTED SESSION;
    ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
    ALTER SYSTEM SET AQ_TM_PROCESSES=0;
    ALTER DATABASE OPEN;
    SHUTDOWN IMMEDIATE;
    SQL> STARTUP RESTRICT  pfile='C:\oracle\product\10.2.0\db_1\database\initORCL.ora';
    ORACLE instance started.
    SQL> alter database national character set INTERNAL_CONVERT UTF8;
    alter database national character set INTERNAL_CONVERT UTF8
    ERROR at line 1:
    ORA-12721: operation cannot execute when other sessions are activeWhy this error when DB is opened in strict and I'm the only user ?
    SQL> select count (*) from v$session;
      COUNT(*)
            20Any solution ?
    Thank you.

    Hi
    This operation is dangerous, please ensure that you have a full backup before doing that operation.
    Please use that order :
    SHUTDOWN IMMEDIATE;
    -- make sure there is a database backup you can rely on, or create one
    STARTUP MOUNT;
    ALTER SYSTEM ENABLE RESTRICTED SESSION;
    ALTER SYSTEM SET JOB_QUEUE_PROCESSES=0;
    ALTER SYSTEM SET AQ_TM_PROCESSES=0;
    ALTER DATABASE OPEN;
    ALTER DATABASE CHARACTER SET <new_character_set>;
    -- a alter database takes typically only a few minutes or less,
    -- it depends on the number of columns in the database, not the
    -- amount of data.
    SHUTDOWN;
    Please note that :
    The command requires the database to be
    open but only one session, the one executing the command, is allowed.
    For the above error conditions Oracle9i will report one of the errors:
    ORA-12719: operation requires database is in RESTRICTED mode
    ORA-12720: operation requires database is in EXCLUSIVE mode
    ORA-12721: operation cannot execute when other sessions are active
    Oracle9i can also report:
    ORA-12718: operation requires connection as SYS
    if you are not connect as SYS (INTERNAL, "/ AS SYSDBA").
    Let us know if this helps.
    regards,
    Hub
    Edited by: Hub on Dec 10, 2008 1:22 PM

  • Onscreen Keyboard appears when shadowing session on 2012R2 Remote Desktop Session Host

    As the title suggests, whenever I shadow a session on our 2012R2 RDSH server, the onscreen keyboard appears.  The taskbar also unlocks.
    Both of these behaviours mean that the user can tell when their session is being shadowed, which I don't always want to be the case - sometimes I want to be able to monitor the session without their knowledge.
    Anyone know how I can stop this from happening?

    Hi,
    Thank you for posting in Windows Server Forum.
    Yeah, we can use the following command where we can take user shadow session without giving him any notification, and no need to approve by the user.
    mstsc.exe /shadow:ID /v:ServerName /control /noConsentPrompt
    But for this, we need to set the following group policy:
    [Computer Configuration | User Configuration]
    \Administrative Templates\Windows Components\Remote Desktop Services\Remote Desktop Session Host\Connections
    Set rules for remote control of Remote Desktop Services user sessions:  Enable
    Select the option: Full Control without User’s permission
    Hope it helps!
    Thanks.
    Dharmesh Solanki
    TechNet Community Support

  • How does c:url tag know when the session is cookieless and thus to redirect

    i have been looking at the source code for c:url tag and can't figure out how they are doing that. I need a way to do that in a jsp, to check if the cookies are allowed or not.

    how does c:url tag know when the session is cookieless and thus to redirecthuh?
    What do cookies have to do with redirecting?
    Cookies get encoded into a URL using the method in HttpServletResponse: response.encodeURL() or encodeRedirectURL().
    That method determines whether or not it prints out the session id as part of the url, or it gets uses cookies.
    You can try: request.isRequestedSessionIdFromCookie().
    If that is true, you know that session cookies are supported (or at least that one was)

Maybe you are looking for