aspose file tools*
The moose likes JSP and the fly likes jsp/ejb connection complications, please help Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp/ejb connection complications, please help" Watch "jsp/ejb connection complications, please help" New topic
Author

jsp/ejb connection complications, please help

bo shen
Greenhorn

Joined: Jul 17, 2002
Posts: 4
Hey, I deployed an EJB on a weblogic 5.1 server. Then I try to call it using JSP with no success. I have been trying for about 9 hours, any help will be greatly appreciated.
The EJB is generated using webgain visualcafe's EJB wizard and it is then deployed to weblogic server using a series of sh scripts.
The EJB has the package mytest, and is placed in the dirctory /home/develop/java/testEJB/
I know the EJB is deployed properly because in the log file it says:
Wed Jul 17 15:36:49 EDT 2002: <EJB JAR deployment /home/develop/java/testEJB/test_WL.jar> EJB home interface:
'mytest.testHome' deployed bound to the JNDI name: 'test'
My simple jsp looks like this:

<%@ page import="javax.servlet.*" %>
<%@ page import="javax.servlet.http.*" %>
<%@ page import="java.io.* %>
<html>
<HEAD>
<TITLE>ejb jsp test</TITLE>
</HEAD>
<Body>
<%
try { %>

<jsp:useBean id="bean1" class="mytest.test" />
<%} catch(Exception e) {
out.println(e.getMessage());
out.println(e.toString());
}
%>
</body></html>

When I load the page I get the error:
cannot instantiate 'mytest.test'
weblogic.utils.NestedRuntimeException: cannot instantiate
'mytest.test' - with nested exception:
[java.lang.ClassNotFoundException: interface
mytest.test : java.lang.InstantiationException:
mytest.test]

now if i change the class="mytest.test" in <jsp:useBean id="bean1" class="mytest.test" /> to some random stuff like class="blabla.blablaaa"
I get this error:
/MAR/ejbtest.jsp(16): Could not create a bean of type: blabla.blalbalaa:
java.lang.ClassNotFoundException: blabla.blablabaa
probably occurred due to an error in /MAR/ejbtest.jsp line 16:

I know it's something to do with path but just cannot figure out what. How is package/class (ie: com.mydomain.ejb) related to the actual location of the ejb (ie: /home/java/ejb/myejb.jar)? Also i found many tutorials about connecting jsp with javabeans, but almost none for jsp with enterprise javabeans.
Thank you,
gagaliya@aol.com
Simon Brown
sharp shooter, and author
Ranch Hand

Joined: May 10, 2000
Posts: 1913
    
    6
The fundamental problem here is that the <jsp:useBean/> action is for instantiating and using JavaBeans, not Enterprise JavaBeans. JavaBeans can be instantiated locally with a default constructor, whereas EJBs need to be remotely instantiated and located.
To use EJBs from JSPs, you need to use the same sort of code that you would from any other J2EE component - be it a servlet or another EJB. In other words, you need to create a new Context and use JNDI to locate the home interface. Let us know if you need code samples of how to acheive this.
As a final note, if you have a copy of Professional JSP 2nd Edition (Wrox Press), the chapter that I wrote takes a look at several different ways of using EJBs from JSPs, namely through scriptlets, JavaBean proxies and custom tags.
In fact, page 247 (and that section) of Chapter 8, Professional JSP Tag Libraries demonstrates how to use EJBs from a JSP - first with scriptlets, and then moves on to wrap up the same functionality as a custom tag.
Hope that helps.
Simon
bo shen
Greenhorn

Joined: Jul 17, 2002
Posts: 4
Ahh thanks! that cleared up everything. I have a followup question. We currently use an oracle database on its own server as the backend, a weblogic application server(stores ejbs and jsps) as the middleware and the users will use normal web browsers to view the JSP. <BR><BR>
What I want to do is to connect the ejb with the database to fetch data then display/format them on/with the JSP. So the JSP and EJB are used only for getting data and displaying data (no storage needed). And we expect about 1000 users load simultaneously at peak hours.<BR><BR>
So my question is: Is it feasible to use javabeans to do this instead of EJBs? and how does deployment differ between javabeans and EJBs on weblogic server <BR><BR>
Thank you,<BR>
Bo

Originally posted by Simon Brown:
The fundamental problem here is that the <jsp:useBean/> action is for instantiating and using JavaBeans, not Enterprise JavaBeans. JavaBeans can be instantiated locally with a default constructor, whereas EJBs need to be remotely instantiated and located.
To use EJBs from JSPs, you need to use the same sort of code that you would from any other J2EE component - be it a servlet or another EJB. In other words, you need to create a new Context and use JNDI to locate the home interface. Let us know if you need code samples of how to acheive this.
As a final note, if you have a copy of Professional JSP 2nd Edition (Wrox Press), the chapter that I wrote takes a look at several different ways of using EJBs from JSPs, namely through scriptlets, JavaBean proxies and custom tags.
In fact, page 247 (and that section) of Chapter 8, Professional JSP Tag Libraries demonstrates how to use EJBs from a JSP - first with scriptlets, and then moves on to wrap up the same functionality as a custom tag.
Hope that helps.
Simon
 
jQuery in Action, 2nd edition
 
subject: jsp/ejb connection complications, please help