📄 client.java
字号:
package com.client;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.rmi.RemoteException;
import java.util.Properties;
import javax.ejb.CreateException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import com.interfaces.CalculatorHome;
import com.interfaces.Calculator;
public class Client {
public static void main(String[] args)
{
Properties properties=new Properties();
properties.setProperty(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
properties.setProperty(Context.PROVIDER_URL,"t3://localhost:7001");
Context context;
try {
context = new InitialContext(properties);
CalculatorHome ch=(CalculatorHome)context.lookup("ejb/Calculator");
Calculator cal=ch.create();
InputStreamReader inputReader = new InputStreamReader(System.in);
BufferedReader reader = new BufferedReader(inputReader);
System.out.print("输入商品总价: ");
double totalPrice = Double.parseDouble(reader.readLine());
double s=cal.calculator(totalPrice);
System.out.print("付款金额: ");
System.out.println(s);
} catch (NamingException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
} catch (CreateException e) {
e.printStackTrace();
} catch (NumberFormatException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
} catch (IOException e) {
// TODO 自动生成 catch 块
e.printStackTrace();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -