tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Novotny <JDNovo...@lbl.gov>
Subject Re: getSession(false)
Date Thu, 26 Apr 2001 18:51:01 GMT

    No- but my lame workaround is to stick something in the session and
test to see if it's null in which case I explicitly set session to null.

e.g.

 HttpSession session = req.getSession(false);

 // Unless a user profile exists, the session is null
 if (session != null) {
   Object user  = session.getAttribute("user");
   if (user == null)
       session = null;
 }


    Jason

Stuart Thomson wrote:

> Did you ever find out what was causing this? I seem to be hitting the
> same problem.
>
> Jason Novotny wrote:
> >
> > Hi,
> >
> >     I'm using the following snippet in my main servlet:
> >
> > public void service(HttpServletRequest req, HttpServletResponse res)
> > throws ServletException, IOException {
> >
> >     HttpSession session = req.getSession(false);
> >      if (session == null) {
> >           System.out.println("session is null");
> >      } else {
> >           System.out.println("session is not null");
> >      }
> >
> > }
> >
> > what I find is that when I go to the servlet, I first see "session is
> > null". Fine by me, and since I passed "false" to getSession, I expect
> > not to have one created. However, when I reload the page, now I get
> > "session is not null". can anyone please explain why getSession(false)
> > actually creates a session, or what I might be doing wrong.
> >
> >     Thanks, Jason
> >
> > --
> > Jason Novotny               novotny@george.lbl.gov
> > Home: (510) 549-0574        Work: (510) 486-8662
> > NERSC Distributed Computing http://www-didc.lbl.gov

--
Jason Novotny               novotny@george.lbl.gov
Home: (510) 610-8360        Work: (510) 486-8662
NERSC Distributed Computing http://www-didc.lbl.gov




Mime
View raw message