cartdataforwindow.java~32~

来自「购物车模块实例。购物车模块可以浏览商品类别;可以根据商品类别浏览商品信息;可以购」· JAVA~32~ 代码 · 共 76 行

JAVA~32~
76
字号
package data;import javax.naming.*;import java.util.Properties;import javax.rmi.PortableRemoteObject;import java.rmi.RemoteException;import cmscartpro.*;public class CartDataForWindow {  CartDataHome cartDataHome = null;  CartData cartData = null;  public CartDataForWindow() {    try{initialize();}catch(Exception ex){ex.printStackTrace();}  }  //EJB的初始化方法  public void initialize() throws Exception {    //创建服务器对象查找类    Context context = getInitialContext();    //取得EJB在服务器的对象    Object ref = context.lookup("CartData");    //取得CartData EJB的创建接口    cartDataHome = (CartDataHome) PortableRemoteObject.narrow(ref,        CartDataHome.class);    //取得CartData EJB的远程接口    cartData = create();  }  //服务器对象查找类的创建方法  private Context getInitialContext() throws Exception {    String url = "t3://bemyfriend:7001";    String user = null;    String password = null;    Properties properties = null;    //初始化联接服务器的属性    try {      properties = new Properties();      properties.put(Context.INITIAL_CONTEXT_FACTORY,                     "weblogic.jndi.WLInitialContextFactory");      properties.put(Context.PROVIDER_URL, url);      if (user != null) {        properties.put(Context.SECURITY_PRINCIPAL, user);        properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);      }      return new InitialContext(properties);    }    catch(Exception e) {      System.out.println("Unable to connect to WebLogic server at " + url);      System.out.println("Please make sure that the server is running.");      throw e;    }  }  //创建Cart EJB的远程接口  public CartData create() throws Exception {    cartData = cartDataHome.create();    return cartData;  }  //取得产品类别数组的方法  public String[][] getCategories() throws Exception{    return cartData.getCategories();  }  //取得产品数组的方法  public Object[][] getProducts(int categoryId) throws Exception{    String[][] oriProducts = cartData.getProducts(categoryId);    String[][] newProducts = new String[oriProducts.length][6];    for(int i = 0; i < oriProducts.length; i++){      newProducts[i][0] = oriProducts[i][0];    //取得产品ID      newProducts[i][1] = oriProducts[i][1];    //取得产品名称      newProducts[i][2] = oriProducts[i][2];    //取得单位数量      newProducts[i][3] = oriProducts[i][3];    //取得产品价格      newProducts[i][4] = new Boolean(false);    //是否购买      newProducts[i][5] = oriProducts[i][3];    //取得产品价格    }    return newProducts;  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?