Converter.java
---------------------------------------------import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.math.*;public interface Converter extends EJBObject {
 
   public BigDecimal dollarToYen(BigDecimal dollars) throws RemoteException;
   public BigDecimal yenToEuro(BigDecimal yen) throws RemoteException;
}ConverterHome.java
---------------------------------------------import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;public interface ConverterHome extends EJBHome {    Converter create() throws RemoteException, CreateException;
}ConverterBean.java
---------------------------------------------import java.rmi.RemoteException; 
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.math.*;public class ConverterBean implements SessionBean {
 
      BigDecimal yenRate = new BigDecimal("121.6000");
      BigDecimal euroRate = new BigDecimal("0.0077");   public BigDecimal dollarToYen(BigDecimal dollars) {      BigDecimal result = dollars.multiply(yenRate);
      return result.setScale(2,BigDecimal.ROUND_UP);
   }   public BigDecimal yenToEuro(BigDecimal yen) {      BigDecimal result = yen.multiply(euroRate);
      return result.setScale(2,BigDecimal.ROUND_UP);
   }   public ConverterBean() {}
   public void ejbCreate() {}
   public void ejbRemove() {}
   public void ejbActivate() {}
   public void ejbPassivate() {}
   public void setSessionContext(SessionContext sc) {}}index.jsp
---------------------------------------------<%@ page import="Converter,ConverterHome,javax.ejb.*, java.math.*, javax.naming.*, javax.rmi.PortableRemoteObject, java.rmi.RemoteException" %>
<%!
   private Converter converter = null;   public void jspInit() { 
      try {
         InitialContext ic = new InitialContext();
         Object objRef = ic.lookup("java:comp/env/ejb/TheConverter");
         ConverterHome home = (ConverterHome)PortableRemoteObject.narrow(objRef, ConverterHome.class);
         converter = home.create();      } catch (RemoteException ex) {
            System.out.println("Couldn't create converter bean."+ ex.getMessage());
      } catch (CreateException ex) {
            System.out.println("Couldn't create converter bean."+ ex.getMessage());
      } catch (NamingException ex) {
            System.out.println("Unable to lookup home: "+ "TheConverter "+ ex.getMessage());
      } 
   }   public void jspDestroy() {    
         converter = null;
   }
%>
<html>
<head>
    <title>Converter</title>
</head><body bgcolor="white">
<h1><b><center>Converter</center></b></h1>
<hr>
<p>Enter an amount to convert:</p>
<form method="get">
<input type="text" name="amount" size="25">
<br>
<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form><%
    String amount = request.getParameter("amount");
    if ( amount != null && amount.length() > 0 ) {
       BigDecimal d = new BigDecimal (amount);
%>
   <p>
   <%= amount %> dollars are  <%= converter.dollarToYen(d) %>  Yen.
   <p>
   <%= amount %> Yen are <%= converter.yenToEuro(d) %>  Euro.
<%
    }
%></body>
</html>

解决方案 »

  1.   

    weblogic 8的帮助里有简单的例子的
    都告诉你怎么部署EJB
    怎么调用现在写的源程序对你没什么用
    你自己还要部署之类的
    看一看帮助吧不要看JSF之类控件的东西
    你只要看看EJB的就行
      

  2.   

    其实你应该求xml的写法。
    代码是小事。
    我曾经为了不小心ejb-jar.xml,weblogic-ejb-jar.xml的一点烦了很久。
      

  3.   

    Object objRef = ic.lookup("java:comp/env/ejb/TheConverter");
    这个 java:comp/env/ejb/TheConverter 是什么啊 关键字?