Session Timeout - How to refresh browser from servlet

P

pramodvr

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.
 
I

Ingo R. Homann

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
 
J

josh.s17

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>
 
C

chris_k

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
 
H

HalcyonWild

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>


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.
 
I

isamura

...
:
: (e-mail address removed) wrote:
: > 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>
:
:
: 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.
:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top