my dog learned polymorphism*
The moose likes Servlets and the fly likes maintaining session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "maintaining session" Watch "maintaining session" New topic
Author

maintaining session

preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Hi,
I need to maintain session for 1 day.How can i do this?
my code to maintain session is:


Am i correct here?whether i have to mention any time here?

Thanks
Remko Strating
Ranch Hand

Joined: Dec 28, 2006
Posts: 893
Use the setMaxInactiveInterval(int interval) method of the HttpSession interface.

The following link will quide you

HttpSession


Remko (My website)
SCJP 1.5, SCWCD 1.4, SCDJWS 1.4, SCBCD 1.5, ITIL(Manager), Prince2(Practitioner), Reading/ gaining experience for SCEA,
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

The session will timeout based on the session timeout element in web.xml or the setMaxInactiveInterval() method can be used to control this time. You can adjust this based on the solution need - declarative or programmatic


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thanks for your reply.But i have to mention the time in milliseconds?(ie)if i need to maintain the session for 24 hours means should i give like this?
Praveen Kumar
Ranch Hand

Joined: Nov 06, 2006
Posts: 133
Hi preethi Ayyappan ,

We can maintain sessions time outs in two ways say thru web.xml or
thru program i.e in your servlet.

Session settings at web.xml effects thru out web application and here we need to set time in minutes.

Where as session.setMaxInactiveInterval() takes in secs where as applicable for that single servlet only.
Karthikeyan Ramaswamy
Ranch Hand

Joined: Apr 30, 2008
Posts: 41
yes, you can give like session.setMaxInactiveInterval(86400000);

and also you can configure in web.xml. like below



In web.xml we can specify in minutes only
In setMaxInactiveInterval we can specify milliseconds only
[ May 19, 2008: Message edited by: Karthikeyan R ]
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thanks.whether i have to mention the set max interval in each servlet wherever i have maintained the session or only in login servlet?
Karthikeyan Ramaswamy
Ranch Hand

Joined: Apr 30, 2008
Posts: 41
if you set session-timeout in web.xml it effects whole web application,
if you set in setMaxInactiveInterval it effect only that particular servlet,
so using session-timeout tag in web.xml is good coding practice.
preethi Ayyappan
Ranch Hand

Joined: Oct 04, 2007
Posts: 518
Thank you for your reply.i will do that
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: maintaining session
 
Similar Threads
simple doubt in session management
session keeps timing out
Unable to compile class for JSP
StateFulSessionBean Problem
Session expires ,user session expires when online