⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cartdataforwindow.java~38~

📁 购物车模块实例。购物车模块可以浏览商品类别;可以根据商品类别浏览商品信息;可以购买商品;可以查看购物车的商品;可以修改购买商品的数量和删除购买的商品。
💻 JAVA~38~
字号:
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);    Object[][] 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] = new Integer(0);       //取得产品价格    }    return newProducts;  }}

⌨️ 快捷键说明

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