You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Kam Lung Leung <kl...@wlwa.com> on 2004/07/07 04:31:48 UTC

java.lang.ClassCastException when casting from Object to a desired object

Hi,

I have a servlet name TestGeneralServiceMenuGenerator that forwards a java
object name, BasicUserInformationDO, to a jsp file that is in another web-app. 
However, these two web-app are in the same VMs. The jsp file keep getting
java.lang.ClassCastException when it trys to casting the object to the desire
object, BasicUserInformationDO. 

Any help are greatly appreciated.
Kam Lung Leung

** code that forwads the BasicUserInformationDO to the jsp file. **

try {
      // Initialize BasicUserInformationDO
      basicUserInformationDO = new BasicUserInformationDO(firstName, lastName,
middleName, iD, subID, numberServices,
 ServiceTypesSubscribed);
      if (basicUserInformationDO == null) {
        log.fatal("basicUserInformationDO is null ");
        throw new java.lang.Throwable("Can not create basicUserInformationDO
object");
      }

      ServletContext context = 
request.getSession().getServletContext().getContext("/VoiceComponentTier");
      if (context == null) {
        log.fatal("ServletContext is null ");
        throw new java.lang.Throwable("Don't have the VoiceComponentTier
Context");
      }
      RequestDispatcher reqDispatcher =
context.getRequestDispatcher("/GeneralServiceMenuGenerator.jsp");
      request.setAttribute("basicUserInfoDO", basicUserInformationDO);
      reqDispatcher.forward(request, response);

    } catch (ServletException servletEx) {
      log.fatal("ServletException : " + servletEx.getStackTrace());
      request.getSession().getServletContext().log("Servlet Exception ", new
Throwable(servletEx.toString()));
    }

** Code on the jsp file that causes java.lang.ClassCastException **

BasicUserInformationDO basicUserInfo =
(BasicUserInformationDO)request.getAttribute("basicUserInfoDO");


** debug information from the log file. **
----- Root Cause -----
java.lang.ClassCastException
        at
org.apache.jsp.GeneralServiceMenuGenerator_jsp._jspService(GeneralServiceMenuGenerator_jsp.java:277)
        at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:137)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:210)
        at
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:295)
        at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
        at
org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:432)
        at
org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:356)
        at
com.wlwa.TestInfra.VoiceComponent.Dispatcher.TestGeneralServiceMenuGenerator.doPost(TestGeneralServiceMenuGenerator.java:95)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:256)
        at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at
org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
        at
org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
        at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
        at
org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2422)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)

---------------------------------------------------------------------
To unsubscribe, e-mail: tomcat-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tomcat-user-help@jakarta.apache.org