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

📄 cartclient.java

📁 JAVA 光盘操作说明 是解压包,直接解压就可以了
💻 JAVA
字号:
package examples;

import java.util.*;
import javax.naming.*;
import javax.rmi.*;

/**
 * Sample client code
 */
public class CartClient {
    public static String url="t3://localhost:7001";
    public static void main(String[] args)  {
        /*
         * Get System properties for JNDI initialization.
         * Obtain the JNDI initial context.
         */
        //Context ctx = new InitialContext(System.getProperties());
        try{
          Context ctx = getInitialContext();
         // System.out.println("Context:"+ctx.lookup("CartHome"));
        /*
         * Get a reference to the home object - the
         * factory for EJB Objects
         */
        CartHome home = (CartHome) PortableRemoteObject.narrow(
            ctx.lookup("CartHome"), CartHome.class);

	// Create a cart, add to it, print it, then remove it
	Cart cart1 = home.create("00001");
        //cart1.add("1", 1);
       // cart1.add("2", 1);
       // cart1.add("3", 1);
        //cart1.purchase();
      //  printCart(cart1);
        cart1.remove();

        // Create an empty cart and print it
	//Cart cart2 = home.create("Tyler Jewell");
       // printCart(cart2);
        }catch(Throwable th){
            th.printStackTrace();
        }
        
    }

    /**
     * Prints out the contents of a shopping cart.
     */
    public static void printCart(Cart cart) throws Exception {
        String owner = cart.getOwner();
        Collection items = cart.getAll();
	Iterator i = items.iterator();
        if (!i.hasNext()) {
            System.out.println(owner + "'s shopping cart is empty:");
        }
        else {
            System.out.println(owner + "'s shopping cart contains:");
            while (i.hasNext()) {
                LineItem item = (LineItem) i.next();
             //   System.out.println("+ " + item.getBook().getBookID());
            }
        }
        System.out.println();
    }
    /**
   * Using a Properties object will work on JDK 1.1.x and Java2
   * clients
   */
  private static Context getInitialContext() throws Throwable {
    
    try {
      // Get an InitialContext
      Properties h = new Properties();
      h.put(Context.INITIAL_CONTEXT_FACTORY,
        "weblogic.jndi.WLInitialContextFactory");
      h.put(Context.PROVIDER_URL, url);
      return new InitialContext(h);
    } catch (NamingException ne) {
      System.out.println("We were unable to get a connection to the WebLogic server at "+url);
      System.out.println("Please make sure that the server is running.");
      throw ne;
    }catch(Throwable th){
        th.printStackTrace();
        throw th;
    }
  }


}

⌨️ 快捷键说明

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