Hai guys,

I am new at jsp.I have made a simple j2ee application in which i am getting class cast exception in PortableRemoteObject.narrow function.

The exception is:

org.apache.jasper.JasperException
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:384)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:297)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:247)
javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)

The root cause is :

java.lang.ClassCastException
com.sun.corba.ee.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:229)
javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:137)
org.apache.jsp.registration_jsp._jspService(registration_jsp.java:59)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:105)
javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:336)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:297)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:247)
javax.servlet.http.HttpServlet.service(HttpServlet.java:860)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
org.apache.catalina.security.SecurityUtil$1.run(SecurityUtil.java:249)
java.security.AccessController.doPrivileged(Native Method)
javax.security.auth.Subject.doAsPrivileged(Subject.java:517)
org.apache.catalina.security.SecurityUtil.execute(SecurityUtil.java:282)
org.apache.catalina.security.SecurityUtil.doAsPrivilege(SecurityUtil.java:165)

The code of the file is :

<%@ page language="java" import="java.sql.,pkg.,javax.ejb.,javax.naming.,javax.rmi.PortableRemoteObject,java.rmi.RemoteException" %>
<html>
<head>
<title></title>
</head>
<body bgcolor="CCCCFF">
<h1><center>Welcome to MyBank</center></h1>
<%
InitialContext initial = new InitialContext();
Object objref = initial.lookup("bankDSN");
pkg.mybankHome vi = (pkg.mybankHome)PortableRemoteObject.narrow(objref,pkg.mybankHome.class);
%>
</body>
</html>

I have read many threads but i was not able to solve this problem.
It has been 2 to 3 weeks that i am struck in this error.
Plz help me with this.

Thanks in advance.

The simple anwser to this is that pkg.mybankHome and PortableRemoteObject.narrow are not of the same type or do not belong to the same class hierarchy. In simple terms u cant do this

Cat cat = (cat)new Dog();

or can you?

Think about this for a sec.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.