473,386 Members | 1,699 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

ClassCastException in JSP and EJB

helo all,

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 m getting exception named "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.servic e(JspServletWrapper.java:370)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:81)

root cause

java.lang.ClassCastException
com.sun.corba.se.internal.javax.rmi.PortableRemote Object.narrow(PortableRemoteObject.java:293)
javax.rmi.PortableRemoteObject.narrow(PortableRemo teObject.java:134)
org.apache.jsp.Verify_jsp._jspService(org.apache.j sp.Verify_jsp:70)
org.apache.jasper.runtime.HttpJspBase.service(Http JspBase.java:97)
javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
org.apache.jasper.servlet.JspServletWrapper.servic e(JspServletWrapper.java:322)
org.apache.jasper.servlet.JspServlet.serviceJspFil e(JspServlet.java:314)
org.apache.jasper.servlet.JspServlet.service(JspSe rvlet.java:264)
javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(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:

Expand|Select|Wrap|Line Numbers
  1.  
  2. VerifyUser.java
  3. ---------------
  4.  
  5. package hina.mahmood;
  6. import javax.ejb.*;
  7. import java.rmi.*;
  8.  
  9. public interface VerifyUser extends javax.ejb.EJBObject
  10. public Boolean Verify(String user, String pswd) throws RemoteException;
  11. }// end interface
  12. *****************************
  13.  
  14. VerifyUserHome.java
  15. -------------------
  16.  
  17. package hina.mahmood;
  18. import javax.ejb.*;
  19. import java.rmi.*;
  20. import javax.ejb.EJBHome;
  21.  
  22. public interface VerifyUserHome extends javax.ejb.EJBHome
  23. {
  24. public VerifyUser create() throws RemoteException,CreateException;
  25. }// end interface
  26. *****************************
  27.  
  28. VerifyUserBean.java
  29. --------------------
  30.  
  31. package hina.mahmood;
  32. import javax.ejb.*;
  33. import java.rmi.*;
  34. import java.sql.*;
  35. import javax.sql.*;
  36. import javax.naming.*;
  37. public class VerifyUserBean implements SessionBean
  38. {
  39. private SessionContext ctx;
  40. public Boolean Verify(String user,String pswd) throws RemoteException
  41. {
  42. int flag=0;
  43. Boolean bool=new Boolean("false");
  44. try{
  45. InitialContext ctx = new InitialContext();
  46. DataSource ds =(DataSource)ctx.lookup("java:honie");
  47. Connection con = ds.getConnection();
  48. Statement stmt = con.createStatement();
  49. String query="Select username,password from hina";
  50. ResultSet rs=stmt.executeQuery(query);
  51.  
  52. while(rs.next())
  53. {
  54. if((rs.getString("username").equals(user))&&(rs.getString("password").equals(pswd)))
  55. {
  56. flag=1;
  57. break;
  58. }
  59. }// end while
  60. }// end try
  61.  
  62. catch(Exception e)
  63. {System.out.println(e);}
  64.  
  65. if(flag==0)
  66. {
  67. bool=new Boolean("false");
  68. return bool;
  69. }
  70.  
  71. else
  72. if(flag==1)
  73. {
  74. bool=new Boolean("true");
  75. return bool;
  76. }
  77.  
  78. return bool;
  79. }// end method
  80.  
  81. public void ejbCreate() throws RemoteException,CreateException
  82. {
  83. }// end method
  84.  
  85. public void setSessionContext(SessionContext ctx)
  86. {
  87. this.ctx=ctx;
  88. }
  89.  
  90. public void ejbPassivate()
  91. {}
  92.  
  93. public void ejbActivate()
  94. {}
  95.  
  96. public void ejbRemove()
  97. {}
  98.  
  99. }// end class
  100. *******************
  101.  
  102. ejb-jar.xml 
  103. -------------- 
  104.  
  105. <?xml version="1.0"?>
  106. <!DOCTYPE ejb-jar PUBLIC '-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN' 'http://java.sun.com/dtd/ejb-jar_2_0.dtd'>
  107.  
  108. <ejb-jar>
  109. <enterprise-beans>
  110. <session>
  111. <display-name></display-name>
  112. <ejb-name>VerifyUser</ejb-name>
  113. <home>hina.mahmood.VerifyUserHome</home>
  114. <remote>hina.mahmood.VerifyUser</remote>
  115. <ejb-class>hina.mahmood.VerifyUserBean</ejb-class>
  116. <session-type>Stateless</session-type>
  117. <transaction-type>Container</transaction-type>
  118. </session>
  119. </enterprise-beans>
  120. </ejb-jar>
  121. ******************************
  122.  
  123. Verify.jsp(page that calls this bean) 
  124. ------------------------------------
  125.  
  126. <%@ page import="java.rmi.*,javax.naming.Context,javax.naming.InitialContext,hina.mahmood.*"%>
  127.  
  128. <%
  129. String username=request.getParameter("user");
  130. String password=request.getParameter("pswd");
  131. InitialContext cxt=new InitialContext();
  132. Object obj=cxt.lookup("VerifyUser");
  133. VerifyUserHome userHome=(VerifyUserHome)javax.rmi.PortableRemoteObject.narrow(obj,VerifyUserHome.class);
  134. VerifyUser vs=userHome.create();
  135. Boolean b=vs.Verify(username,password);
  136. boolean bool=b.booleanValue();
  137. if(bool)
  138. response.sendRedirect("main.jsp");
  139. else
  140. response.sendRedirect("error.jsp");
  141.  
  142. %>
  143. ***********************
  144.  
  145. msaccess-ds.xml
  146. ---------------
  147.  
  148. <datasources>
  149. <local-tx-datasource>
  150. <jndi-name>honie</jndi-name>
  151. <!-- format of URL is "jdbc:odbc:DSNNAME" -->
  152. <connection-url>jdbc:odbc:honie</connection-url>
  153. <driver-class>sun.jdbc.odbc.JdbcOdbcDriver</driver-class>
  154. <user-name></user-name>
  155. <password></password>
  156. </local-tx-datasource>
  157.  
  158. </datasources>
  159. ********************* 
  160.  
  161.  

i dont know, what mistake i m doing now.:(
do i need to set any class path or anything else? currently i have set my class path to j2ee.jar, my other servlet taht 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
Dec 31 '07 #1
2 1998
Dude you forgot put typecast for VerifyUser while getting object from Home.Please check the following highlighted JSP code where you did a mistake.



<%@ page import="java.rmi.*,javax.naming.Context,javax.nami ng.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.PortableRemoteO bject.narrow(obj,VerifyUserHome.class);
VerifyUser vs=(VerifyUser )userHome.create();
Boolean b=vs.Verify(username,password);
boolean bool=b.booleanValue();
if(bool)
response.sendRedirect("main.jsp");
else
response.sendRedirect("error.jsp");

%>
Jan 2 '08 #2
1st of all, thanku so much 4 considering my question, bcoz no one was doing that. :(

what u have told above, i have tried that, but my problem is still there. :(
i think problem is not in this line of code, bcoz even if i remove this line and the lines under it, even then i m getting the same exception. what i guess is that, problem lies with the line just above the one that u have pointed out .i.e

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

this line is creating all the problem(i think so) but i dont know how to get rid of this problem. if u can give me any further suggestions for fixing this error, plz do that. i'll be very grateful to u.

thanks.
Jan 2 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Christine Zhou | last post by:
Hi, We have a customized HttpServletRequest object, when we run the application on webshpere 4.0.7,got a ClassCastException on this object, but was Ok on WAS4.0.1, Anyone know why, is this...
3
by: Jon-Paul Dobson | last post by:
Hi, We have an applet that implements the MouseListener interface but when trying to add the applet to the glasspane of another applet a classcastexception is thrown. This all seemed to work...
5
by: Casper B | last post by:
Since I am only able to pass simple beans around using my Web Service framework, I wonder how to incorporate business logic around these beans. My idea was to let my Beans be the base class and...
1
by: Chris | last post by:
I use websphere connection pooling and had a failure attempting a CLOB.createTemporary. tempClob = CLOB.createTemporary(conn, true, CLOB.DURATION_SESSION); Here's an excerpt of the exception...
1
by: Johannes Lebek | last post by:
Hi there, I made some changes to my XSL stylesheet and now Xalan 2.5.1 is facing ClassCastExceptions. I'm pretty sure, that the changes I made should work (they are quite complicated -- I'd like...
1
by: kanthi84 | last post by:
hi, while i was trying to insert value into a blob column, i got an exception saying java.lang.ClassCastException: com.evermind.sql.OrclResultSet
1
by: cristina1234 | last post by:
I have a constructor that takes a java.awt.Component as an argument: public DesignContainer(Component comp,...){...} If I pass it a javax.media.opengl.GLCanvas object,it takes it,but the...
1
by: mrityunjay11 | last post by:
String description = ""; String query1 = ""; int grade_autoid,count=0; rSet1= DBHelper.getQueryResult(query); %> ...
4
by: eazyigz | last post by:
I downloaded Junit 4.5 and am using the TestRunner class to test the AllTests class in the junit/tests package. I am issuing the following command at a DOS prompt: java -classpath junit-4.5.jar;....
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.