Solved

JSP page interact with an EJB session bean

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How To Remove a Principal from HttpServletRequest 4 53
servlet cookie finding by name 1 90
eclipse luna javeEE perspecive missing 5 118
servlet example 17 59
Arrow Electronics was searching for a KVM  (Keyboard/Video/Mouse) switch that could display on one single monitor the current status of all units being tested on the rack.
This article discusses how to implement server side field validation and display customized error messages to the client.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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