You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Dean A. Hoover" <dh...@rochester.rr.com> on 2004/04/19 17:18:10 UTC

detecting session timeout

Any suggestions on how to detect
session timeouts? I am experimenting
with extending TilesRequestProcessor
(I'm using struts 1.1 and tiles). Here's
an example of the kind of thing I would
like to detect: I have a multipage registration
process. Suppose a user gets halfway through
and then goes away for some reason (lunch?).
They come back and their session has timed
out. This means that the data that was gathered
and placed in the session on previous forms is
gone. The validator framework then complains
about missing data from the previous pages. I
just want to put up a special page indicating that
they took too long to register. I need this same
basic session in a number of places, so I really
need a general solution. Any ideas?

Dean Hoover


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: detecting session timeout

Posted by Kurt Overberg <ku...@hotdogrecords.com>.
I use an HttpSessionAttributeListenen to get a callback when a 
session times out.  There's a method called "attributeRemoved", 
which gets called when something is removed from someones session.
I look for a standard value (username) that should never get 
removed from the users session (until it either timesout, or they 
logout).  I use this and attributeAdded to maintain a list, so I 
can tell who's "logged in" to my site.

public class SessionLister implements HttpSessionAttributeListener
{
public void attributeAdded(HttpSessionBindingEvent ev)
{
     // add user to static list
     if (ev.getName().equals("username")){
  	users.put(ev.getValue(), ev.getValue());
     }
}

public void attributeRemoved(HttpSessionBindingEvent ev)
{
    if (ev.getName().equals("username")){
     log.info("SESSION LOGGED OUT OR EXPIRED: "
		+ ev.getName() + " = "
		+ ev.getValue());
      users.remove(ev.getValue());
    }
}

private HashMap getList(HttpSessionEvent hse)
{
   HttpSession session = hse.getSession();
   ServletContext context = session.getServletContext();
   HashMap users = (HashMap)
              context.getAttribute("com.app.userlist");
   if (users == null)
   {
	users = new HashMap();
	context.setAttribute("com.bzzagent.userlist", users);
   }
   return users;
}

}

...then put this into your web.xml

<listener>		  <listener-class>com.app.SessionLister</listener-class>
</listener>

...so you could use this to build and maintain a list of people who 
started the flow (put something in their session) and do something 
else with the user if they time out (decrement a counter, etc).

Hope this helps.

/kurt



brati.sankarghosh@tcs.com wrote:

> 
> We have done a similar thing with filter. You put a check in the filter 
> to redirect to an error page if the session is not present in the 
> request. this will also prevent a user to access the site without login in.
> Filters however is only available with servlet 2.3
> 
> Brati Sankar Ghosh
> Tata Consultancy Services
> Mailto: brati.sankarghosh@tcs.com
> Website: http://www.tcs.com
> 
> 
> *"Khalid K." <gr...@maikada.com>*
> 
> 04/20/2004 07:13 AM
> Please respond to
> "Struts Users Mailing List" <us...@struts.apache.org>
> 
> 
> 	
> To
> 	"'Struts Users Mailing List'" <us...@struts.apache.org>
> cc
> 	
> Subject
> 	RE: detecting session timeout
> 
> 
> 	
> 
> 
> 
> 
> 
> You can store an attribute in session when you initially start the session
> Subsquent checks for that attribute on EACH request will check if that
> Attribute doesn't exist...session has expired or they are not logged on etc.
> 
> Of course the key to this is to put a hook on RequestProcessor to run this
> snipt
> For each request...if you do this correctly...the request won't even make it
> to your action
> You can redirect them to whatever page you like...
> 
> We have similar code but we use Struts 1.0 so we have extended ActionServlet
> and have
> Written the processPreProcess()   (I think..that is what the method is
> called..can't recall the actual name)
> 
> Khalid
> 
> 
> -----Original Message-----
> From: Dean A. Hoover [mailto:dhoover@rochester.rr.com]
> Sent: Monday, April 19, 2004 8:18 AM
> To: struts-user@jakarta.apache.org
> Subject: detecting session timeout
> 
> 
> Any suggestions on how to detect
> session timeouts? I am experimenting
> with extending TilesRequestProcessor
> (I'm using struts 1.1 and tiles). Here's
> an example of the kind of thing I would
> like to detect: I have a multipage registration
> process. Suppose a user gets halfway through
> and then goes away for some reason (lunch?).
> They come back and their session has timed
> out. This means that the data that was gathered
> and placed in the session on previous forms is
> gone. The validator framework then complains
> about missing data from the previous pages. I
> just want to put up a special page indicating that
> they took too long to register. I need this same
> basic session in a number of places, so I really
> need a general solution. Any ideas?
> 
> Dean Hoover
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> 
> ---
> Incoming mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.659 / Virus Database: 423 - Release Date: 4/15/2004
> 
> 
> ---
> Outgoing mail is certified Virus Free.
> Checked by AVG anti-virus system (http://www.grisoft.com).
> Version: 6.0.659 / Virus Database: 423 - Release Date: 4/15/2004
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
> 
> 
> ForwardSourceID:NT0000584A    
> 
> 
> ------------------------------------------------------------------------
> 
> DISCLAIMER: The information contained in this message is intended only and solely for the addressed individual or entity indicated in this message and for the exclusive use of the said addressed individual or entity indicated in this message (or responsible for delivery
> of the message to such person) and may contain legally privileged and confidential information belonging to Tata Consultancy Services. It must not be printed, read, copied, disclosed, forwarded, distributed or used (in whatsoever manner) by any person other than the addressee. 
> Unauthorized use, disclosure or copying is strictly prohibited and may constitute unlawful act and can possibly attract legal action, civil and/or criminal. The contents of this message need not necessarily reflect or endorse the views of Tata Consultancy Services on any subject matter.
> Any action taken or omitted to be taken based on this message is entirely at your risk and neither the originator of this message nor Tata Consultancy Services takes any responsibility or liability towards the same. Opinions, conclusions and any other information contained in this message 
> that do not relate to the official business of Tata Consultancy Services shall be understood as neither given nor endorsed by Tata Consultancy Services or any affiliate of Tata Consultancy Services. If you have received this message in error, you should destroy this message and may please notify the sender by e-mail. Thank you.
> 
> 
> 
> 
> ------------------------------------------------------------------------
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: detecting session timeout

Posted by Erik Price <er...@mac.com>.
On Apr 20, 2004, at 12:30 AM, brati.sankarghosh@tcs.com wrote:

>
> We have done a similar thing with filter. You put a check in the 
> filter to redirect to an error page if the session is not present in 
> the request. this will also prevent a user to access the site without 
> login in.

Although you have to put a "return" after your redirect, just in case 
the browser doesn't respect the redirect header (this prevents the 
filter from allowing execution to continue on the resource it is 
protecting, something which has actually happened to me in the absence 
of a "return" on Tomcat 4.x).



-- 
Erik Price

<http://erikprice.com/>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: detecting session timeout

Posted by br...@tcs.com.
We have done a similar thing with filter. You put a check in the filter to 
redirect to an error page if the session is not present in the request. 
this will also prevent a user to access the site without login in.
Filters however is only available with servlet 2.3

Brati Sankar Ghosh
Tata Consultancy Services
Mailto: brati.sankarghosh@tcs.com
Website: http://www.tcs.com



"Khalid K." <gr...@maikada.com> 
04/20/2004 07:13 AM

Please respond to
"Struts Users Mailing List" <us...@struts.apache.org>


To
"'Struts Users Mailing List'" <us...@struts.apache.org>
cc

Subject
RE: detecting session timeout






You can store an attribute in session when you initially start the session
Subsquent checks for that attribute on EACH request will check if that 
Attribute doesn't exist...session has expired or they are not logged on 
etc.

Of course the key to this is to put a hook on RequestProcessor to run this
snipt
For each request...if you do this correctly...the request won't even make 
it
to your action
You can redirect them to whatever page you like...

We have similar code but we use Struts 1.0 so we have extended 
ActionServlet
and have
Written the processPreProcess()   (I think..that is what the method is
called..can't recall the actual name)

Khalid


-----Original Message-----
From: Dean A. Hoover [mailto:dhoover@rochester.rr.com] 
Sent: Monday, April 19, 2004 8:18 AM
To: struts-user@jakarta.apache.org
Subject: detecting session timeout


Any suggestions on how to detect
session timeouts? I am experimenting
with extending TilesRequestProcessor
(I'm using struts 1.1 and tiles). Here's
an example of the kind of thing I would
like to detect: I have a multipage registration
process. Suppose a user gets halfway through
and then goes away for some reason (lunch?).
They come back and their session has timed
out. This means that the data that was gathered
and placed in the session on previous forms is
gone. The validator framework then complains
about missing data from the previous pages. I
just want to put up a special page indicating that
they took too long to register. I need this same
basic session in a number of places, so I really
need a general solution. Any ideas?

Dean Hoover


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.659 / Virus Database: 423 - Release Date: 4/15/2004
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.659 / Virus Database: 423 - Release Date: 4/15/2004
 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


ForwardSourceID:NT0000584A 

RE: detecting session timeout

Posted by "Khalid K." <gr...@maikada.com>.
You can store an attribute in session when you initially start the session
Subsquent checks for that attribute on EACH request will check if that 
Attribute doesn't exist...session has expired or they are not logged on etc.

Of course the key to this is to put a hook on RequestProcessor to run this
snipt
For each request...if you do this correctly...the request won't even make it
to your action
You can redirect them to whatever page you like...

We have similar code but we use Struts 1.0 so we have extended ActionServlet
and have
Written the processPreProcess()   (I think..that is what the method is
called..can't recall the actual name)

Khalid


-----Original Message-----
From: Dean A. Hoover [mailto:dhoover@rochester.rr.com] 
Sent: Monday, April 19, 2004 8:18 AM
To: struts-user@jakarta.apache.org
Subject: detecting session timeout


Any suggestions on how to detect
session timeouts? I am experimenting
with extending TilesRequestProcessor
(I'm using struts 1.1 and tiles). Here's
an example of the kind of thing I would
like to detect: I have a multipage registration
process. Suppose a user gets halfway through
and then goes away for some reason (lunch?).
They come back and their session has timed
out. This means that the data that was gathered
and placed in the session on previous forms is
gone. The validator framework then complains
about missing data from the previous pages. I
just want to put up a special page indicating that
they took too long to register. I need this same
basic session in a number of places, so I really
need a general solution. Any ideas?

Dean Hoover


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.659 / Virus Database: 423 - Release Date: 4/15/2004
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.659 / Virus Database: 423 - Release Date: 4/15/2004
 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org