Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: how we can do that when one user is log suuceefully (servlets)

  1. #1
    Junior Member
    Join Date
    Sep 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default how we can do that when one user is log suuceefully (servlets)

    hii to all

    first i want to elaborate the scenario
    it is like that when one user for example user A HAS USERNAME:ANURAG & PASSWORD: UITK

    HE IS ALREADY LOGIN SUCCESSFULLY IN APPLICATION HE SURFING THE WEBSITE.

    THEN if another person B TRYING TO LOGIN INTO THE APPLICATION BY THE USE OF THE PERSON A USERNAME AND PASSWORD

    then during this i want that person B GET A MESSAGE LIKE THIS "U ARE ALREADY LOGIN " .

    MEANS HOW WE ENSURE THAT SEESION MANAGEMENT VERIFY THE UNIQUE USER_ID MEANS NO OTHER CAN BE LOG ON WHEN THAT USERID IS ALREADY LOG IN.



    the session because each client will gets unique session and they cannot be cross-checked. You'll either need to keep information in the application context to check against, or perhaps even in the DB.


    means let us suppose we has a table current_user

    which has field user_id , application_id , session _id ,

    and the sessionid is generated from container when user A is login for their user_id and this information is save in this table like this
    test , school, jsesso12345 ,

    m eans when user is login then we can check it for user_id exist or not in that table but my doubt is that when the second time user is login then this user_id is already exist for same user so how can he will be able to login for the second time .

    please suggest me


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,237
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: how we can do that when one user is log suuceefully (servlets)

    If I follow, your requirement is that a user can only be logged on one computer at a time.
    1) You record the session id in a database when a user logs in.
    2) When another client attempts to login with those same credentials the session id's do not match and the connection is refused.
    3) The problem as I see it is that when the initial user's session expires the user may not have the same session id when they revisit - thus will not be able to login. To overcome this, look into using an HttpSessionBindingListener, adding it to the session when the user logs in. According to the API this will be fired when the session expires, and can be used to reset the flag in the database.

  3. #3
    Junior Member
    Join Date
    Oct 2011
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: how we can do that when one user is log suuceefully (servlets)

    Well you would probably need another db fields as a timedate

    `logged_in` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,

    select id from table where username='blah' and
    (unix_timestamp(now())) time1 ,(unix_timestamp(logged_in)+300)




    String id = session.getId();
    //get current id - compare this to output of your db - if not found then its a new user.

    Also when they log out - before doing log out - to store a status in the same table to say logged_out=1;

    But they may close the browser so by checking the session id if the same


    Learn Java by Examples - How do I count number of online users?

    Have a look here for some more guidance on active sessions.

Similar Threads

  1. constructors in servlets
    By the light in forum JavaServer Pages: JSP & JSTL
    Replies: 4
    Last Post: June 29th, 2011, 10:32 AM
  2. constructors in servlets
    By the light in forum Java Servlet
    Replies: 3
    Last Post: June 27th, 2011, 04:13 AM
  3. changes made to JSP or servlets
    By the light in forum JavaServer Pages: JSP & JSTL
    Replies: 2
    Last Post: May 30th, 2011, 08:19 AM
  4. Help with JSP and Servlets
    By skyinfire305 in forum JavaServer Pages: JSP & JSTL
    Replies: 10
    Last Post: July 29th, 2010, 08:06 AM
  5. [SOLVED] How to link two servlets?
    By bhmadhukar in forum Java Servlet
    Replies: 4
    Last Post: May 19th, 2009, 08:24 AM