?
Solved

JSP page interact with an EJB session bean

Posted on 2006-11-30
5
Medium Priority
?
1,044 Views
Last Modified: 2010-08-05
Please help...
why it does not work
============================================================================



<%@ page import="javax.naming.*, javax.rmi.PortableRemoteObject, com.u8.servicerequest.SrTypeProcessorLocal, com.fujitsu.au.servicerequest.SrTypeProcessorLocalHome, com.fujitsu.au.servicerequest.util.SrTypeModel" %>

<%!
 //declare a "global" reference to an instance of the home interface of the session bean
 SrTypeProcessorLocal srTypeHome=null;

 public void jspInit() throws ServletException {
   //obtain an instance of the home interface
   try {
     Context ctx = new InitialContext();
     Object ref = ctx.lookup("java:comp/env/ejb/SrTypeProcessorBean");
       srTypeHome = (SrTypeProcessorLocal)PortableRemoteObject.narrow(ref,SrTypeProcessorLocal.class);
   } catch (CreateException e) {
         e.printStackTrace();
         throw new ServletException(e.toString());
   } catch (NamingException e) {
         e.printStackTrace();
         throw new ServletException(e.toString());
   }
 }
%>

<%
 //instantiate the session bean
  SrTypeProcessorLocal srType = srTypeHome.create();
 //invoke the remote methods
%>
0
Comment
Question by:LeanMoreTryMore
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 29

Expert Comment

by:bloodredsun
ID: 18053167
Please post the stackTrace or error that is printed.
0
 
LVL 14

Expert Comment

by:boonleng
ID: 18053168
Can you post the error log.
0
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 1500 total points
ID: 18056344
Hi,

look at the sample code here...i hope it might help you
http://www.jguru.com/faq/view.jsp?EID=5314
http://www.jguru.com/faq/view.jsp?EID=917

R.K
0
 

Author Comment

by:LeanMoreTryMore
ID: 18065075
Im using the MVC design pattern.
The javabean is used to retrieves the home interface of the session bean by performing a lookup operating in the naming system, and which invokes the bean’s business methods. and then via the session to invoke the entity bean to retreive the data from the underlying database

See below javabean
=============

public class SrTypeProxy {
   private SrTypeProcessorLocal srType;

   public SrTypeProxy() throws Exception {
          init();
   }
   public void init() throws Exception {
   
     // Lookup the enterprise bean
     try {
       InitialContext ctx = new InitialContext();
         Object ob = ctx.lookup("java:comp/env/ejb/SrTypeProcessorBean");
         SrTypeProcessorLocalHome home = ( SrTypeProcessorLocalHome ) PortableRemoteObject.narrow( ob, SrTypeProcessorLocalHome.class );
         //Initialize the enterprise bean
         srType = home.create();
     } catch ( Exception e ) {
         throw new Exception("Error instantiating SrTypeProcessorBean EJB" + e.toString());
     }
   }  
   
   public SrTypeModel[] getSrType()throws Exception {
         
         SrTypeModel[] srTypeModel;
    try {
            srTypeModel = srType.viewSrType();      
    }catch (Exception re){
          throw new Exception("Fail to retrive service types");
    }
    return srTypeModel;
   }
}

===========================================================================
The error is: java.lang.InstantiationException: ID018236: Cannot instantiate bean. java.lang.ClassNotFoundException: class com.fujitsu.au.servicerequest.beans.SrTypeProxy : java.lang.Exception: Error instantiating SrTypeProcessorBean EJBcom.sap.engine.services.jndi.persistent.exceptions.NameNotFoundException: Path to object does not exist at java:comp, the whole lookup name is java:comp/env/ejb/SrTypeProcessorBean.

0
 
LVL 8

Expert Comment

by:mhunts
ID: 18072508
You need to include the jar file that contains SrTypeProxy in your classpath.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Learn how to use the free Acronis True Image app to easily transfer data between iPhones and Android phones.
What's worse than having your data encrypted by ransomware? Getting attacked by a so-called "wiper," which simply destroys the data and offers you no hope of ever seeing it again.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question