session expires

Posted on 2014-08-08
Last Modified: 2014-08-14

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?
Question by:Rocking
    LVL 27

    Expert Comment

    Are you using Tomcat? If yes, then is it stand alone? Or is Apache web server in front of it?

    Author Comment

    Yes, tomcat only configured through eclipse
    LVL 27

    Accepted Solution

    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

    LVL 27

    Expert Comment

    I tested again with the code I posted. The session seems to last.  I waited for 132 minutes with no problem.
    LVL 30

    Expert Comment

    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

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    I had a project requirement for a displaying a user workbench .This workbench would consist multiple data grids .In each grid the user will be able to see a large number of data. These data grids should allow the user to 1. Sort 2. Export the …
    Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
    Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
    The viewer will learn how to implement Singleton Design Pattern in Java.

    730 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now