Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2005

Tip: Looking for answers? Try searching our database.

Session Timeout - How to refresh browser from servlet

Thread view: 
pramodvr@hotmail.com - 08 Nov 2005 09:02 GMT
Hi group,

I am relatively new to servlets and web development even though I have
fairly good Java experience. Here is my question which is
straightforward.

How to refresh the browser with a message "your session has expired"
once the servlet noticed inactivity of ,say, 30 minutes. I read that
this is possible with an applet listening to the servlet. Is there any
other better solution. Now the question becomes more generic- how to
pass an object from the servlet to the client without a request from
client.

Thanks for any help.

regards

Pramod.
Ingo R. Homann - 08 Nov 2005 09:21 GMT
Hi,

> How to refresh the browser with a message "your session has expired"
> once the servlet noticed inactivity of ,say, 30 minutes. I read that
> this is possible with an applet listening to the servlet. Is there any
> other better solution.

There are other solutions (you must decide, if they are "better" in your
context):

- JavaScript
- a Meta-Referesh which periodically starts a new request (perhaps in an
"invisible" frame)
- wait until the user requests a new page and *then* display the message
- ...

> Now the question becomes more generic- how to
> pass an object from the servlet to the client without a request from
> client.

Impossible. But the workarounds mentioned above may work as well
(depending on your demands).

Ciao,
Ingo
josh.s17@gmail.com - 08 Nov 2005 09:23 GMT
Rather than use an applet to keep the session alive you can adjust the
session timeout in your deployment descriptor (web.xml). It is
specified in minutes. You can make it 24 hours or whatever you require.

<session-config>
     <session-timeout>30</session-timeout>
   </session-config>
HalcyonWild - 08 Nov 2005 09:45 GMT
> Rather than use an applet to keep the session alive you can adjust the
> session timeout in your deployment descriptor (web.xml). It is
[quoted text clipped - 3 lines]
>       <session-timeout>30</session-timeout>
>     </session-config>

How about this, from the j2ee api.

void setMaxInactiveInterval(int interval)
         Specifies the time, in seconds, between client requests
before the servlet container will invalidate this session.

Set it to 1800 for half hour. Now when client sends request, you can
check if session exists, see request.getSession(boolean) method.
Also , if you cannot control creation of a new session, you can find
some use for session.getId() or getCreationTime(). Check the api.
isamura - 08 Nov 2005 23:18 GMT
: > Rather than use an applet to keep the session alive you can adjust the
: > session timeout in your deployment descriptor (web.xml). It is
[quoted text clipped - 14 lines]
: Also , if you cannot control creation of a new session, you can find
: some use for session.getId() or getCreationTime(). Check the api.

I have used both approaches and find session control somewhat tricker than with another technology.
I don't know if that is the case in general.

If you have a user logged in then the session can be set with a user attribute to indicate the
session's active state. When it does expire you will know by checking for the "active" state
attribute. Of course you will have to do this check with each request.

On a related note, when using the setMaxInactiveInterval(900) method I have noticed the session seem
to change periodically while I am accessing links and refreshing pages on my dev site. It looks like
the max inactive interval is not resetting when there are active requests. I am using Tomcat 4.1 and
j2se 1.4. Has anyone observed this problem?

.K
chris_k - 08 Nov 2005 09:33 GMT
Hi,

> How to refresh the browser with a message "your session has expired"
> once the servlet noticed inactivity of ,say, 30 minutes.

You may use JavaScript to periodically make requests (using finction
setTimeout(...)) to some session-checker servlet. By reading the
servlet reponse, you can deside if client's HTTP session has expired
and redirect to a page showing this info.

HTH,
chris
Viv - 08 Nov 2005 09:51 GMT
Ever heard of Ajax, may be your solution exist in that.
visit the link below, it may be useful learning Ajax.

http://en.wikipedia.org/wiki/AJAX


Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.