Solved

JSP page interact with an EJB session bean

Posted on 2006-11-30
5
1,034 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
Comment Utility
Please post the stackTrace or error that is printed.
0
 
LVL 14

Expert Comment

by:boonleng
Comment Utility
Can you post the error log.
0
 
LVL 23

Accepted Solution

by:
rama_krishna580 earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
You need to include the jar file that contains SrTypeProxy in your classpath.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
A safe way to clean winsxs folder from your windows server 2008 R2 editions
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now