session expires


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

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

Are you using Tomcat? If yes, then is it stand alone? Or is Apache web server in front of it?
RockingAuthor Commented:
Yes, tomcat only configured through eclipse
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" %>
   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 ${}<br/>

Open in new window


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
I tested again with the code I posted. The session seems to last.  I waited for 132 minutes with no problem.
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
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

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.