• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

How to implement timeout functionaily using JSP and Servlets

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have the following scenario. But i am not getting any idea how to implement it. please help me . I would be very thankful if anyone can send code samples.

Following is my problem.

I will be having some users who can access my web site. To access my web site they have to pay some money . Based on the money that users paid to me i will allocate a time limit to them (and it will be stoed in DB)to access my web site. Once they exceeds the time limit they should get a alert message saying that your time is over and please recharge your account.

I mean , Suppose a user paid 100Rs to me. Then say i allocated 100minutes to him. So he can access my site for 100 minutes. Once he crosses 100 min i should not allow the user to access my site any more . And i have to display an alert message to the user saying that his time is exceeded.

Also if he logs in and logs out in 20 min (say) , then i have to update the time limit in DB to 80 minutes.

I have to implement this using java,jsp,java script and servlets.
So please help me out if you have any ideas.


Regds,
Sreek
 
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by sreek ss:
I have to implement this using java,jsp,java script and servlets.
So please help me out if you have any ideas.



Can you user Applet?
 
Sreek Gupta
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
I do not have any applets in my application.
Is it not possible using JSP , Servlets ?
If not possible , Can you please advise me how can i do this using applets.
As i am new to these technologies , please help me with code samples.

Regds,
Sreek
 
Chetan Parekh
Ranch Hand
Posts: 3640
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well without Applet also it is achievable.

Tell me the business requirements so that I can suggest according to that.
 
Ranch Hand
Posts: 2874
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It should be better done on server-side. You can always apply some logic.

Well, i am listing down some steps

- Get the time alloted for that particular user from DB while authenticating user.
- Record the current time just after a successful authentication and call it login time
- Take difference between the current and login time upon each request and compare that with the time alloted
- invalidate the session accordingly and redirect the user to some message page

Are you getting me??
 
Sreek Gupta
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
Following are my business requirements.

1. Initially users pay money to me to access my website. Then i will create a entry in Database for that user. Based on the money he paid to me i will allocate duration to him. Typically my database table looks as follows.

LOGIN_TABLE:
-----------
USER_NAME VARCHAR2(100)
PASSWORD VARCHAR2(100)
AMOUNT NUMBER(10)
DURATION NUMBER(10)

Upon registration administrator populates this table.

2. After payment, he is eligible to access my website. He can logon to my site by entering username and password which has been created at login time.

3. Take the scenario now. Suppose user 'A' has paid 100Rs to me. Then i will register him into the system. Username, Password, Amount, Duration will be populated in the database.
Now say following is the entry present in Database.

USER_NAME 'A'
PASSWORD '****'
AMOUNT 100
DURATION 6000000 milli seconds i,e (60 minutes)

4. Now user 'A' can log into the system by entering username and password. If he logout the system in 1000000 milli seconds then database has to be updated accordingly. That means DURATION field in the database has to be updated to 5900000 milli seconds. He can come next time and use the remaining time.

5. When user is left with 3 minutes , then he has to be displayed with a alert saying that only 3 minutes left and to recharge again.

6. If he continue to use my website more than 60 minutes without recharging , then he has to be disconnected and should not be allowed to login again until he recharges again.

I am not getting how to proceed. Do we need to access the database indefinitely to get the duration every second? What could be the best way in these kind of scenarios.

Please help me with code samples. Also please let me know if there is any confusion in the requirements.

Regds,
Sreek
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would look at the HTTP Session Listener:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSessionListener.html

There are also some methods in HTTP Session for determining how long a session has been active:
http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/http/HttpSession.html

Remember, HTTP is a stateless environment.
This means that you have no way of knowing if someone's browser (or internet connection) has crashed or if they wandered to another site without logging out. If you are charging them by the minute, you will probably want set a real short session-timeout value.
Normally this would be a source of irritation to the user but compared with being charged for time that they're not using, having to log in after 5 minutes of inactivity probably isn't so bad. With a little Javascript, you could write a poller that hits the site every n seconds to keep the session active as long as they have the browser pointed to your site.

I wrote a small demo app that monitors user sessions.
Some of that code might be interesting to you.
http://simple.souther.us/not-so-simple.html
Look for SessionMonitor.
 
Sheriff
Posts: 67753
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"sreek ss",

There aren't many rules that you need to worry about here on the Ranch, but one that we take very seriously regards the use of proper names. Please take a look at the JavaRanch Naming Policy and adjust your display name to match it.

In particular, your display name must be a first and a last name separated by a space character, and must not be obviously fictitious.

Thanks!
bear
JavaRanch Sheriff
 
Ranch Hand
Posts: 1026
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I haven't gone through the entire thread and here are my suggestions

Check getCreationTime() method of HttpSession. With this method you can limit a user to say 10 minutes before the session expires. I haven't implemented this.

There are lot of free code in javascript with which you can easily do this. But I am not sure whether this would be an appropriate solution.

Javascript Solution
Time limit on viewing document script

keep us informed about your progress.
[ March 09, 2006: Message edited by: Vishnu Prakash ]
 
Roses are red, violets are blue. Some poems rhyme and some don't. And some poems are a tiny ad.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic