You must have a reference to the servlet or servletcontext somehow.

You could do something like this (you should store the servlet not the session):

protected void process(HttpServletRequest request, HttpServletResponse response)
 throws IOException, ServletException {
 HttpSession session= request.getSession(true);
 SessionHandler.storeCurrentSession(session);
 super.process(request, response);
 SessionHandler.removeCurrentSession();
}

And the SessionHandler is this:

public class SessionHandler 
{
 private static java.util.HashMap _hmSessions = new java.util.HashMap();

public static HttpSession getCurrentSession()
{
 return (HttpSession)_hmSessions.get(Thread.currentThread().getName());
}
public static void removeCurrentSession()
{
 _hmSessions.remove(Thread.currentThread().getName());
}
public static void storeCurrentSession(HttpSession session)
{
 _hmSessions.put(Thread.currentThread().getName(), session);
}
}

Then you can always call SessionHandler.getCurrentSession()
As long as you are in the same thread as the current request, which is very likely

Johan


----- Original Message ----- 
From: "Deping Chian" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, January 23, 2001 2:50 PM
Subject: GenericDataSource usage in non-servlet classes


> Could somebody tell me how to use GenericDataSource in non-servlet classes?
> 
> I could access the pool in action servlets using GenericDataSource ds =
> (GenericDataSource)
> servlet.findDataSource(null). But my my non-struts-related classes cannot
> access the pool.
> 
> Thanks,
> 
> Deping
> 
> 
> 
> 

Reply via email to