session expires

Hi,

I have configured session value as "-1" so that in my application session never expires?
But if i access my page within the application after few hours and get value from session like
request.getSession.getAttribute("ID")

It throws null pointer exception? what can be the cause and why it is throwing null pointer when the session should never expire as per web.xml?
RockingAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

rrzCommented:
Are you using Tomcat? If yes, then is it stand alone? Or is Apache web server in front of it?
0
RockingAuthor Commented:
Yes, tomcat only configured through eclipse
0
rrzCommented:
I am testing with stand alone Tomcat on my desktop. My initial test passed. It lasted an hour. Tomorrow I will try for a longer period. Here is my test JSP.
<%@ page import="java.util.Date" %>
<%
   if(session.isNew())session.setMaxInactiveInterval(-1);
   long now = new Date().getTime();
   long last = session.getLastAccessedTime();
   long inactivePeriod = (now - last)/60000;
%>
The MaxInactiveInterval is ${pageContext.session.maxInactiveInterval}<br/>
Is the requested session ID still valid? ${pageContext.request.requestedSessionIdValid}<br/>
Inactive period was <%=inactivePeriod%> minutes <br/>
The session id is ${pageContext.session.id}<br/>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
rrzCommented:
I tested again with the code I posted. The session seems to last.  I waited for 132 minutes with no problem.
0
Mayank SAssociate Director - Product EngineeringCommented:
Why do you want the session to never expire? That's like a memory leak and over a prolonged duration the application will bomb and give an OutOfMemoryError
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.