Babar,

This functionality used to be part of HttpSessionContext, and you could do
session.getSessionContext().getSession("name").  That whole class is now deprecated as
it was not a scalable solution.

You can achieve something similar (with the same scalability issues, too) by
registering session references at application scope (seems a bit counterintuitive, I
know).  You would have to be careful about creating a memory leak situation (i.e. you
need to remove the session references from application scope when the sessions
expire).  I would propose something along these lines [disclaimer--I haven't tried this
code]:

    public class Watchdog implements HttpSessionBindingListener {
        private ServletContext application;
        public Watchdog(ServletContext application) {
            this.application = application;
        }
        public void valueBound(HttpSessionBindingEvent e) {
            application.setAttribute(e.getSession().getId(), e.getSession());
        }
        public void valueUnbound(HttpSessionBindingEvent e) {
           application.removeAttribute(e.getSession().getId());
        }
    }

And in your servlet, register the session at some convenient point:
    session.putValue("watchdog", new Watchdog(getServletContext()));

For any session that the above line has been called for, you can look up a session as
an application scope variable:
    HttpSession session = (HttpSession) getServletContext().getAttribute(sessionID);

The scalability issue is that you cannot register your sessions beyond the current
application scope in which they are running, so servlets running under a separate
application scopes won't be able to access each other's sessions.

Wes


David Mossakowski wrote:

> Check the API and see there's no way to do it.  getValue only gets named value that
> has been put into session before.  The session itself is handed by the engine.
>
> dav.e
>
> Babar Bhutta wrote:
>
> > Hi Everybody,
> >         I am looking for a way to get the value of my session using the
> > session id instead of session. The reason I am trying to do this, is because
> > sometime I couldn't find my session which I stored in some Servlet. I tried
> > to use the method getValue("sessionName") but it returns null. Kindly help
> > me out in the regard! I am using IBM websphere in Visual Age Enterprise
> > Edition 2.0

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
FAQs on JSP can be found at:
 http://java.sun.com/products/jsp/faq.html
 http://www.esperanto.org.nz/jsp/jspfaq.html

Reply via email to