aspose file tools*
The moose likes Servlets and the fly likes session question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "session question" Watch "session question" New topic
Author

session question

Jean Miles
Ranch Hand

Joined: Aug 20, 2003
Posts: 53
If I am using a cookie to manage session state, If I launch another IE from start menu what determines if that IE browser window will be using the session with cookie or it will be a new session?
Tim Baker
Ranch Hand

Joined: Oct 04, 2003
Posts: 541
it will be a new session. you could of kept all this in one thread you know.
if you want to keep them logged in in multiple windows you have to write and read your own cookies


Kim Jong II (North Korea's Dear Leader) said:Nuclear weapons don't kill people, people kill people.
Marty Hall
Author
Ranch Hand

Joined: Jan 02, 2003
Posts: 111
If I am using a cookie to manage session state, If I launch another IE from start menu what determines if that IE browser window will be using the session with cookie or it will be a new session?

Good question. Let's assume that you are using the default way of session tracking (which is where the server sends the JSESSIONID without a max age, so the cookie is kept in the browser's memory, not stored on disk).
  • If the user opens a new IE window from the Start Menu or desktop icon, that new IE window will not share the in-memory cookies with the old window, so thus will be in a new session from the Java perspective.
  • If the user opens a new IE window from the old window's File menu or by hitting Control-N, that new IE window will share the in-memory cookies and will be part of the same Java session.


  • Also, don't forget that the spec advertises the name of the cookie that will be used (JSESSIONID). So, you can resend that cookie with a max age, and then use the normal session tracking API after that.
    Cheers-
    - Marty


    Java training and consulting
    sunitha reghu
    Ranch Hand

    Joined: Dec 12, 2002
    Posts: 937
    Originally posted by Marty Hall:

  • If the user opens a new IE window from the Start Menu or desktop icon, that new IE window will not share the in-memory cookies with the old window, so thus will be in a new session from the Java perspective.


  • Suppose a user is filing a registration form which contains two or more pages. And if the user opens one more window and submitting two forms , how to track the user?
    For example filing a tax returns which system doesnt want the user to submit twice.
  • If the user opens a new IE window from the old window's File menu or by hitting Control-N, that new IE window will share the in-memory cookies and will be part of the same Java session.

  • [/list]
    So if the user shares the same session, how to track the user?
    Jean Miles
    Ranch Hand

    Joined: Aug 20, 2003
    Posts: 53
    thanks marty, this info has help me alot. I am also interested on questions mazha thulli had asked.
    [ November 13, 2003: Message edited by: Jean Miles ]
    Pradeep bhatt
    Ranch Hand

    Joined: Feb 27, 2002
    Posts: 8919

    So if the user shares the same session, how to track the user?

    Both the windows will be using the same session IDs.


    Groovy
    Ko Ko Naing
    Ranch Hand

    Joined: Jun 08, 2002
    Posts: 3178
    Originally posted by mazha thulli:
    Suppose a user is filing a registration form which contains two or more pages. And if the user opens one more window and submitting two forms , how to track the user?
    For example filing a tax returns which system doesnt want the user to submit twice.

    Surely we have to define a flag that shows whether the user has already submitted or not... And remember that the data source that saves the flag should be protected from concurrent accessing...


    Co-author of SCMAD Exam Guide, Author of JMADPlus
    SCJP1.2, CCNA, SCWCD1.4, SCBCD1.3, SCMAD1.0, SCJA1.0, SCJP6.0
    Pradeep bhatt
    Ranch Hand

    Joined: Feb 27, 2002
    Posts: 8919

    I think she was talking about 2 concurrent submits.
    Ko Ko Naing
    Ranch Hand

    Joined: Jun 08, 2002
    Posts: 3178
    Originally posted by Pradeep Bhat:
    I think she was talking about 2 concurrent submits.

    If so, we have to use the servlets, which implement SingleThreadModel. But for servlets not implementing the SingleThreadModel interface, if the
    service method (or methods such as doGet or doPost which are dispatched to the service method of the HttpServlet abstract class) has been defined with the synchronized keyword....
    It is strongly recommended that Developers not synchronize the service method (or methods dispatched to it) in these circumstances because of detrimental effects on performance....
    Pradeep bhatt
    Ranch Hand

    Joined: Feb 27, 2002
    Posts: 8919

    We can store the submitted application's user ID in some data structure in the aplication context. If some one submits it successfully, make an entry in the data structure. We can also detect multiple entires at the database level
    sunitha reghu
    Ranch Hand

    Joined: Dec 12, 2002
    Posts: 937
    Originally posted by Ko Ko Naing:

    If so, we have to use the servlets, which implement SingleThreadModel. But for servlets not implementing the SingleThreadModel interface, if the
    service method (or methods such as doGet or doPost which are dispatched to the service method of the HttpServlet abstract class) has been defined with the synchronized keyword....
    It is strongly recommended that Developers not synchronize the service method (or methods dispatched to it) in these circumstances because of detrimental effects on performance....


    So are you suggesting to use SingleThreadModel interface?
    Pradeep im not talking abt concurrent submits. That I can always be solved by setting a flag. Im pasting Jeans question in another thread which basically same in this question.

    Problem is that I don't want same user in multiple IE windows updating the same data at the same time. So if I can restrict an user to only one session in the application, not multiple then I can solve the problem. However, I couldn't think of another way to handle this other than i keeping track of user session in database. If user has entry in database then send back a message that user has session in another browser window. To make sure database entry is removed, when the session terminates put a listener on session so when it invalidates I removed the entry in the database. However there are problems with this, if the user can close the IE window, the session is active until it timeout in the meantime the user launch another IE window with new session, since the entry is still in the database the code will denied them.
     
    It is sorta covered in the JavaRanch Style Guide.
     
    subject: session question