dcsimg
"ClassCastException", help required....
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   star_mahmood
Posted On:   Tuesday, January 1, 2008 11:43 AM

hello i am working with JSP and EJBs. i have written a simple code for verifying username and password of user by using session beans. my problem is that i am getting the following exception: "ClassCastException". Exception is as follows: [exception] type Exception report message description The server encountered an internal error () that prevented it from fulfilling this request. exception org.apache.jasper.JasperException org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspS   More>>

hello


i am working with JSP and EJBs. i have written a simple code for verifying username and password of user by using session beans. my problem is that i am getting the following exception:

"ClassCastException". Exception is as follows:




[exception]



type Exception report



message



description The server encountered an internal error () that prevented it from fulfilling this request.



exception



org.apache.jasper.JasperException

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:370)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)



root cause



java.lang.ClassCastException

com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)

javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)

org.apache.jsp.Verify_jsp._jspService(org.apache.jsp.Verify_jsp:70)

org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:97)

javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:322)

org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:314)

org.apache.jasper.servlet.JspServlet.service(JspServlet.java:264)

javax.servlet.http.HttpServlet.service(HttpServlet.java:810)

org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)



note The full stack trace of the root cause is available in the Apache Tomcat/5.5.9 logs.



[/exception]



i have change code a little bit which i m presenting for ur consideration:



			



VerifyUser.java

---------------



package hina.mahmood;

import javax.ejb.*;

import java.rmi.*;



public interface VerifyUser extends javax.ejb.EJBObject

{

public Boolean Verify(String user, String pswd) throws RemoteException;

}// end interface

*****************************



VerifyUserHome.java

-------------------



package hina.mahmood;

import javax.ejb.*;

import java.rmi.*;

import javax.ejb.EJBHome;



public interface VerifyUserHome extends javax.ejb.EJBHome

{

public VerifyUser create() throws RemoteException,CreateException;

}// end interface

*****************************



VerifyUserBean.java

--------------------



package hina.mahmood;

import javax.ejb.*;

import java.rmi.*;

import java.sql.*;

import javax.sql.*;

import javax.naming.*;


public class VerifyUserBean implements SessionBean

{

private SessionContext ctx;

public Boolean Verify(String user,String pswd) throws RemoteException

{

int flag=0;

Boolean bool=new Boolean("false");

try{

InitialContext ctx = new InitialContext();

DataSource ds =(DataSource)ctx.lookup("java:honie");

Connection con = ds.getConnection();

Statement stmt = con.createStatement();

String query="Select username,password from hina";

ResultSet rs=stmt.executeQuery(query);



while(rs.next())

{

if((rs.getString("username").equals(user))&&(rs.getString("password").equals(pswd)))

{

flag=1;

break;

}

}// end while

}// end try



catch(Exception e)

{System.out.println(e);}



if(flag==0)

{

bool=new Boolean("false");

return bool;

}



else

if(flag==1)

{

bool=new Boolean("true");

return bool;

}



return bool;

}// end method


public void ejbCreate() throws RemoteException,CreateException

{

}// end method



public void setSessionContext(SessionContext ctx)

{

this.ctx=ctx;

}



public void ejbPassivate()

{}



public void ejbActivate()

{}



public void ejbRemove()

{}



}// end class

*******************



ejb-jar.xml

--------------



<?xml version="1.0"?>













VerifyUser

hina.mahmood.VerifyUserHome

hina.mahmood.VerifyUser

hina.mahmood.VerifyUserBean

Stateless

Container







******************************



Verify.jsp(page that calls this bean)

------------------------------------



<%@ page import="java.rmi.*,javax.naming.Context,javax.naming.InitialContext,hina.mahmood.*"%>



<%

String username=request.getParameter("user");

String password=request.getParameter("pswd");

InitialContext cxt=new InitialContext();

Object obj=cxt.lookup("VerifyUser");

VerifyUserHome userHome=(VerifyUserHome)javax.rmi.PortableRemoteObject.narrow(obj,VerifyUserHome.class);

VerifyUser vs=userHome.create();

Boolean b=vs.Verify(username,password);

boolean bool=b.booleanValue();


if(bool)

response.sendRedirect("main.jsp");


else

response.sendRedirect("error.jsp");



%>

***********************



msaccess-ds.xml

---------------







honie



jdbc:odbc:honie

sun.jdbc.odbc.JdbcOdbcDriver











*********************








i dont know, what mistake i m doing.:(

do i need to set any class path or anything else?
currently i have set my class path to j2ee.jar, my other servlet that do not involve ejbs are working perfectly.



my directory structue is as follows:



hm.war-> WEB-INF(folder) & Verify.jsp



WEBINF->classes(folder) & web.xml
classes->hina(folder)->mahmood(folder)-> VerifyUser.class & VerifyUserBean.class & VerifyUserHome.class




my beans.jar contains:



beans.jar->msaccess-ds.xml & META-INF & and package hina(folder)->mahmood(folder)->VerifyUser.class & VerifyUserBean.class & VerifyUserHome.class
META-INF->ejb-jar.xml





plz plz plz help me. its really very important 4 me.

thanks



   <<Less

Re: "ClassCastException", help required....

Posted By:   Anonymous  
Posted On:   Wednesday, March 5, 2008 01:42 AM

make sure u have the stubs and skeleton. Ur client program should have access to the stubs. U will get the stubs during deployment. it should be added in the classpath.
About | Sitemap | Contact