Solved

Finding If a Session  is Valid using the Session ID

Posted on 2002-03-18
3
181 Views
Last Modified: 2010-04-01
Hello All,
     I am currently working on a web application where in
a user is allowed to edit a particular record. I will have
to restrict 2 users from editing the same record, for this
reason i am using the Session Id of the user to know which
user is editing a particular record.

     I have a seperate table which stores the entries like
the record (unique identified) and the session id. Each
time a person is about to edit or delete a particular
record i go and see if  that particular record is being
edited by another user.

    Now the problem is if the session has expired, i don't
have a control of the record which i had created. So if
another user tries to update or delete he is still not able to edit or delete that particular record.

    Now i have the Session Id of the user who started
editing that particular record, now i will have to find
out if the session is valid.

    Can any one help me out to solve the above problem.
I am current using tomcat 3.2.3 on Red Hat Linux .


V. Ramkumar.

any other user
0
Comment
Question by:V_Ram
  • 2
3 Comments
 
LVL 6

Accepted Solution

by:
kotan earned 100 total points
ID: 6879091
You can use event/listener method to delete the record which had created. Here is the steps:

Create an object which implement HttpSessionBindingListener. This object will be stored in a session.
Then, you should implement the valueBound() and valueUnBound() method. The valueUnbound() method will
be trigger if this object being unbound (This happen when the object is being replaced and session  
is invalid). In here, you can get the invalid session and delete away the record from the database.

public class BoundObj implements HttpSessionBindingListener {
   public BoundObj() {}
   public void valueBound(HttpSessionBindingEvent be) {
        // Will be trigger when this object being bound.
   }

   public void valueUnBound(HttpSessionBindingEvent be) {
       HttpSession hs = be.getSession();
       String userid = hs.getAttribute("userid");
       String sessionid = hs.getID();
       ....
       // Delete database record.
   }
}
At the time the user login which you create a new session, put the bound object in that session.
session.setAttribute("boundobj", new boundObj());
0
 

Author Comment

by:V_Ram
ID: 6882031
Hello Kotan,
   It Did Work , thanks for you timely help. By the way
does this class gets a message when the Browser is closed.

V. Ramkumar.


     
0
 
LVL 6

Expert Comment

by:kotan
ID: 6882038
if the browser is closed,then it will wait until the session expire to get the message.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Can I clean log of  running tomcat 7 server ? 3 127
How to group array of objects ? 5 69
constructor overloading 2 86
jsp insert to database example 2 43
Learn how to PXE Boot both BIOS & UEFI machines with DHCP Policies and Custom Vendor Classes
The Nano Server Image Builder helps you create a custom Nano Server image and bootable USB media with the aid of a graphical interface. Based on the inputs you provide, it generates images for deployment and creates reusable PowerShell scripts that …
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question