关注
我是用JB新建的EJBClient来测试的,这种情况是要写环境文件吧
我是用JB新建的EJBClient来测试的,这种情况是要写环境文件吧
解决方案 »
- 网上商城数据库设计书
- java学习
- 上不去myEclipse的官网,想下myEclipse7.0,有没有国内的下载地址或者给邮一个
- 搞怪的事情,调用同一个方法,参数值完全相同,结果不一样.cglib问题,待高手出马~
- 高分求助:域名访问丢失Session的问题(Lotus和WebSphere)
- hibernate eclipse奇怪问题
- 关于Mapbuilder的问题
- 没招了!在hibernate中使用jotm
- jdom中,在写入物理文件时,怎样能做到只修改某个Element,而不是重写整个物理文件
- 年底不好找工作呀。
- 为什么启动J2EE服务器的时候,总是出现OUT OF ENVIRONMENT SPACE?
- 要不要为对象序列化?请高手给我解惑!
import FundManagerBean.*;
import javax.naming.*;
import javax.rmi.*;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.text.*;
import java.util.*;
import javax.ejb.*;
import java.rmi.*;public class FundManagerClient extends JFrame implements ActionListener
{
double balance = 0;
JTextField amount = new JTextField(10);
JButton addFunds = new JButton("Add Funds");
JButton withdrawFunds = new JButton("Withdraw Funds");
String msg = "Current account balance: ";
String strBal = "0";
JLabel status;
FundManager manager;
NumberFormat currencyFormatter;
public FundManagerClient()
{
super("Fund Manager");
}
public static void main(String[] args)
{
new FundManagerClient().init();
}
public void init()
{
buildGUI();
//匿名类
addWindowListener(new WindowAdapter(){
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});
addFunds.addActionListener(this);
withdrawFunds.addActionListener(this);
createFundManager();
try
{
currencyFormatter = NumberFormat.getCurrencyInstance();
String currencyOut = currencyFormatter.format(0);
status.setText(msg + currencyOut);
}
catch(Exception re)
{
re.printStackTrace();
}
pack();
show();
}
public void buildGUI()
{
GridBagLayout gl = new GridBagLayout();
GridBagConstraints gc = new GridBagConstraints();
Container f_container = getContentPane();
f_container.setLayout(gl);
gc.fill = GridBagConstraints.BOTH;
JLabel f_label = new JLabel("Enter Amount");
gl.setConstraints(f_label, gc);
f_container.add(f_label);
gc.gridwidth = GridBagConstraints.REMAINDER;
gl.setConstraints(amount, gc);
f_container.add(amount);
gl.setConstraints(addFunds, gc);
f_container.add(addFunds);
gl.setConstraints(withdrawFunds, gc);
f_container.add(withdrawFunds);
status = new JLabel(msg);
gl.setConstraints(status, gc);
f_container.add(status);
}
public void actionPerformed(ActionEvent e)
{
String str = amount.getText();
if (str.equals(""))
return;
try
{
if (e.getSource() == addFunds)
{
balance = (double)manager.addFunds(balance,
Double.parseDouble(amount.getText()));
currencyFormatter = NumberFormat.getCurrencyInstance();
strBal = currencyFormatter.format(balance);
status.setText(msg + strBal);
}
else if (e.getSource() == withdrawFunds)
{
balance = (double)manager.withdrawFunds(balance,
Double.parseDouble(amount.getText()));
currencyFormatter = NumberFormat.getCurrencyInstance();
strBal = currencyFormatter.format(balance);
status.setText(msg + strBal);
}
}
catch(Exception re)
{
re.printStackTrace();
}
}
private static InitialContext ctx;
private static InitialContext getWebSphareContextInfo()
{
InitialContext ctx = null;
try
{
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,
// "com.ibm.ejs.ns.jndi.CNInitialContextFactory");
"com.ibm.websphere.naming.WsnInitialContextFactory");
prop.put(Context.PROVIDER_URL, "iiop://localhost:2809");
ctx = new InitialContext(prop);
}
catch(NamingException ne)
{
System.out.println(ne);
System.exit(0);
}
catch(Exception e)
{
System.out.println(e);
System.exit(0);
}
return ctx;
}
public void createFundManager()
{
try
{
InitialContext ctx = getWebSphareContextInfo();
Object objref = ctx.lookup("FundManagerHome");
FundManagerHome home = (FundManagerHome)PortableRemoteObject.narrow(
objref, FundManagerHome.class);
manager = home.create();
}
catch(NamingException ne)
{
System.out.println("Naming Exception caught: " + ne);
System.exit(0);
}
catch(CreateException ce)
{
System.out.println("Create Exception caught: " + ce);
System.exit(0);
}
catch(RemoteException re)
{
System.out.println("Remote Exception caught: " + re);
System.exit(0);
}
catch(Exception e)
{
System.out.println("Exception caught: " + e);
System.exit(0);
}
}
}
Object objref = ctx.lookup("FundManagerHome");
这1句抛出的异常
Object objref = ctx.lookup("FundManagerHome");
这1句抛出的异常假如你的Bean的名字叫FundMangerBean,那么上句话改成
Object objref = ctx.lookup("FundManagerBean");
试试