我niit老師也搞不定的問題

uioouiy發表於2004-07-08
--------------------------------------------------------------------------------
我用jsp呼叫javabean再呼叫ejb 部署透過 一切正常!
但是當我直接部署ejb後 因是用j2ee部署的 也返回了.jar做classpath了 雖正常但是用client程式訪問的時候 就會出現classcastexception
//client
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.naming.*;
import javax.rmi.*;

public class CalculatorClient extends JFrame
{
public static int w=500;
public static int h=95;
public static String str="Earnest Bank Welcomes You";
Container c;
JLabel l,result;
JTextField t;
JButton b;
public static String value;
public static double dbl;
public static double amt;
public CalculatorClient()
{
super(str);
c = getContentPane();
c.setLayout(new GridLayout(2,2,2,2));
l = new JLabel("Enter the amount in Dollars($)");
c.add(l);
t = new JTextField(10);
c.add(t);
b = new JButton("Calculate");
c.add(b);
result = new JLabel();
c.add(result);
b.addActionListener(new addEvent());
setSize(w,h);
show();
}
class addEvent implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
value = t.getText();
dbl = Double.parseDouble(value);
try{
Context ic = new InitialContext();
java.lang.Object obj = ic.lookup("MyCalculator");
CalculatorHome home = (CalculatorHome)PortableRemoteObject.narrow(obj,CalculatorHome.class);
Calculator calc = home.create();
amt = calc.dollarToRs(dbl);
result.setText("Result(RS.)" + String.valueOf(amt));
}
catch(Exception t)
{
System.out.println(t);
}
}
}
public static void main(String args[])
{
new CalculatorClient();
}

}

我估計是CalculatorHome home = (CalculatorHome)PortableRemoteObject.narrow(obj,CalculatorHome.class);出現問題了 小弟就想問一下 CalculatorHome.class因放在什麼位置? 到底是什麼問題 希望大家幫忙啊



相關文章