aspose file tools*
The moose likes Servlets and the fly likes Sessions created by magic? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Sessions created by magic?" Watch "Sessions created by magic?" New topic
Author

Sessions created by magic?

Monica Moncho
Ranch Hand

Joined: Dec 01, 2004
Posts: 31
Hi,

I have a servlet that destroys the current session with invalidate. To get the session I am using getSession(false). The thing is, I am calling this servlet many times in a row and it always seems to destroy a new session. I am displaying the session ID for debugging.

How is this session created each time if I am not creating it. What I am looking for is destroying the session and then not having a new one the next time I call to destroy it.

Anybody knows why I seem to always get a new session? I'm totally confused now.

thanks
Cameron Wallace McKenzie
author and cow tipper
Saloon Keeper

Joined: Aug 26, 2006
Posts: 4968
    
    1

Check out your JSP pages. Many JSP pages have tags that automatically create a session when they are used. If you are forwarding to a JSP page, it may have an innocuous tag that is creating a new session right after your Servlet kills it.
[ August 27, 2006: Message edited by: Bear Bibeault ]
Monica Moncho
Ranch Hand

Joined: Dec 01, 2004
Posts: 31
Thanks. I will investigate that. I am forwarding to a JSP, but I have only this on it:

<%@ page import="java.util.*" %>
<%@include file="top.htm" %>

Who knows, maybe somewhere else. I will recheck my pages to see if I can find it.

Thanks!
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

By default JSPs create a session (if one doesn't already exist).
To stop this behaviour you need to add the following directive to your JSP:


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
wood burning stoves
 
subject: Sessions created by magic?