- From: S.Ramaswamy <srswamy@giasdl01.vsnl.net.in>
- Date: Sat, 30 May 1998 10:17:08 +0530
- To: <www-jigsaw@w3.org>
- Message-Id: <01bd8b86$011258a0$743a36ca@matrix>
I am using the following configuration a) Jigsaw Web Server from w3c Consortium that supports Servlets b) JDK1.2 beta 3 I have two servlets 1) MxSessionManager servlet 2) MxBrowse servlet User invokes MxSessionManager first. This gets inited allright. Then user invokes MxBrowse servlet. Within MxBrowse init method, I want the reference to MxSessionManager instance. MxSessionManager maintains session details which is required each and every subsequent servlet call. I am getting the referenc as given below ServletContext sc = conf.getServletContext(); MxSessionManager sm = (MxSessionManager)sc.getServlet("MxSesssionManager"); This gives me ClassCastException. I have checked the Class object of the returned object of getServlet("MxSessionManager"). This is shown the same as MxSessionManager. Option 1 tried -------------------- However, if I cast the returned value to HttpServlet, or GenericServlet the superclasses of MxSessionManager, then there is no ClassCastException. HttpServlet hs = (HttpServlet)getServlet("MxSessionManager"); // works fine Option 2 tried -------------------- I have tried subclassing MxSessionManager say as MxLogin extends MxSessionManager. Now I do MxSessionManager sm = (MxSessionManager)sc.getServlet("MxLogin"); still no use. ------------------------------------------------Code Snippet ------------------------------------------- public abstract class HttpServlet extends GenericServlet implements Servlet { ...... } public class MxSessionManager extends HttpServlet { ........ } public class MxSessionHttp extends HttpServlet { public void init( ServletConfig conf ) { try { super.init( conf ); } catch( ServletException e ) { } try { MxSessionManager sessionManager = (MxSessionManager) ((conf.getServletContext()).getServlet("MxSessionManager")); } catch( Exception e ) { ************ I am getting ClassCastException here. *********** } } ................. } Can someone help please? Thanks
Received on Saturday, 30 May 1998 00:47:25 UTC