Solved

JSP page interact with an EJB session bean

Posted on 2006-11-30
5
1,036 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
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 500 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Display the newly inserted values 3 75
spring AOP 6 85
memory representation of int[][][] a=new int[2][][]; 10 60
how to add new optional parameter to JSP 1 41
If you thought ransomware was bad, think again! Doxware has the potential to be even more damaging.
Employees depend heavily on their PCs, and new threats like ransomware make it even more critical to protect their important data.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

773 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