You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by vienzo <vi...@gmail.com> on 2006/04/06 14:34:57 UTC

Tomcat's getSession(true) returning null

Hi people,

i'm experiencing a strange session behaviour in several of my projects
running on Tomcat 5.5.12. When the page is being rendered inside servlet's
doGet (or doPost, actually it doesn't matter), i call
request.getSession(true) many times in order to get data, and at random
times it suddenly returns null, eventhough by specification it MUST return a
valid session. That, of course, crashes my application in random time
intervals. Probably anybody has experienced the same and could help me solve
this problem?? I'm totally confused with tomcat, because not a single forum
has a post related to this. Here is some of my code:


// Servlet class
public class IntranetServlet extends HttpServlet {
    // called from doGet && doPost
    public void syncGet(HttpServletRequest request, HttpServletResponse
response) {
        ResourceManager resourceManager = new ResourceManager(this, request,
response);
        VelocityEngine ve = ResourceManager.getTemplateEngine();
        ....
    }
}

// Code which causes null to pop-up
public class ResourceManager {
    private static HttpServlet servlet;
    private HttpServletRequest request;
    private HttpServletResponse response;

    public ResourceManager(HttpServlet aServlet, HttpServletRequest
aRequest, HttpServletResponse aResponse) throws FileUploadException {
        servlet = aServlet;
        request = aRequest;
        response = aResponse;
        ....
    }

    public HttpSession getSession() {
        HttpSession session = request.getSession(true);
        // null, randomly
        System.out.println(session);
        return session;
    }



it's just a standard session handling, nothing else. And there are no code
that explicitly does anything else but session.set/get/removeAttribute on
the session.

i'll appreciate any help alot.


vienzo
--
View this message in context: http://www.nabble.com/Tomcat%27s-getSession%28true%29-returning-null-t1405617.html#a3783393
Sent from the Tomcat - User forum at Nabble.com.

Re: Tomcat's getSession(true) returning null

Posted by vienzo <vi...@gmail.com>.
okay, i was a bit wrong about the problem. now it is solved, finally.

the problem was that i have an object "User", which has an aggregated
"ResourceManager" object, which, in turn, has the fields of request,
response and etc.. i've been storing that User object in the session and not
updating those request and response references, what made them stale and
unusable. at some points in my application i had a call to
resourceManager.getSession().getAttribute("CurrentUser") and on that
received object invoked getRequest().getSession() which actually refered to
an old request and as a result the session was null, eventhough i would use
getReq..().getSession(true). Quite a dissapointment.

Sorry for your time

vienzo
--
View this message in context: http://www.nabble.com/Tomcat%27s-getSession%28true%29-returning-null-t1405617.html#a3800428
Sent from the Tomcat - User forum at Nabble.com.