deprecated servlet session management: getSessionContext();

D

david

Per the documentation
HttpSessionContext context = session.getSessionContext();
is deprecated due to security reasons and there is no specified
replacement. The Java Servlet Programming book had a prototype session
management code segment that has been useful. How do we do session
management now? Where are good tutorials/code segments which will perform
session management similarly to the previous method?
 
E

Erwin Moller

david said:
Per the documentation
HttpSessionContext context = session.getSessionContext();
is deprecated due to security reasons and there is no specified
replacement. The Java Servlet Programming book had a prototype session
management code segment that has been useful. How do we do session
management now? Where are good tutorials/code segments which will perform
session management similarly to the previous method?

Hi David,

Maybe this can help you:

implements HttpSessionBindingListener

If you use HttpSessionBindingListener on ANY class, two methods will be
called:

public void valueBound(HttpSessionBindingEvent sbe){
// called when this object is bound to a session
// use sbe.getSession() to get the session.
}

public void valueUnbound(HttpSessionBindingEvent sbe){
// called when object is unbound to session
}


From session you can get the ServletContext like this:
sbe.getSession().getServletContext()

I think if you define an object in the ServletContext that handles all
sessions, you can code the functionality you are looking for.

Good luck,
Erwin Moller
 
D

david

"Erwin Moller"
Hi David,

Maybe this can help you:

implements HttpSessionBindingListener

If you use HttpSessionBindingListener on ANY class, two methods will be
called:

public void valueBound(HttpSessionBindingEvent sbe){
// called when this object is bound to a session
// use sbe.getSession() to get the session.
}

public void valueUnbound(HttpSessionBindingEvent sbe){
// called when object is unbound to session
}


From session you can get the ServletContext like this:
sbe.getSession().getServletContext()

I think if you define an object in the ServletContext that handles all
sessions, you can code the functionality you are looking for.

Good luck,
Erwin Moller
Thanks... can you point to any good articles/books/texts that discuss
"replacement" techniques (i.e. deprecated API -> new API) for session
management.
 
E

Erwin Moller

Thanks... can you point to any good articles/books/texts that discuss
"replacement" techniques (i.e. deprecated API -> new API) for session
management.

No, sorry, cannot be of any help there.

Sun didn't deprecate it to annoy you, I think they deprecated it because
there was no use after all. (I am not sure of this though....)

I have some advise:
I think you can figure it out yourself if you just get a little bit angry
and try it with ServletContext or HttpSessionBindingListener.

HttpSessionBindingListener:
What are you expecting from HttpSessionContext that cannot be replaced by
another custummade class that can hold ANY enumeration, or whatever suits
your needs?

ServletContext:
You have a look ServletContext (or APPLICATION from a JSP point-of-view) if
you need a place that is accecable from ALL SERVLETS AND JSP.

If you have no clue what I am talking about, just look in the API, and try a
little, like this:
Just try to store some class in ServletContext, and you will see you can
retrieve it by the name you stored it under from other servlets and
sessions too. (You have to cast it from Object to your classdefinition
first.)

I am quite sure you can retrieve any functionality of the deprecated
sessionContext with one of the above, or both, methods.

Hope this helps you.

Good luck,
Erwin Moller

PS: There still is a valid SessionContext but it concerns EJB, I guess that
is not what you are looking for. Just wanted to mention it. If you don't
use EJB, don't look into it, it will confuse you a lot.
http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/ejb/SessionContext.html
 
D

david

Thanks much Erwin... It's not so much that I can't figure out how to do
session management with the info you provided and the API doc, it's just
that it seems like there should be some "examples" of how to implement the J
Servlet Programming session management example (expiring sessions, etc) with
the new API so that what I end up doing is semi-conventional... Oh well...
again, thanks very much for all the pointers!

"Erwin Moller"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top