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

📄 cartclient.java

📁 这是《精通EJB3.0》一书中的代码
💻 JAVA
字号:
package examples.stateful.client;

import javax.ejb.NoSuchEJBException;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import examples.stateful.interfaces.Cart;

public class CartClient {
	public static void main(String[] args) {
		try {
			InitialContext ic = new InitialContext();
			System.out.println("Adding items to cart, then removing...");
			for (int i=0;i<2;i++) {
				Cart cart = (Cart)ic.lookup(Cart.class.getName());
				cart.addItem();
				cart.addItem();
				System.out.println("Number of items in the cart: "+cart.getItems());
				try {
					try {
						if (i==0) {
							cart.remove1();
						}
						else {
							cart.remove2();						
						}
					}
					catch (Exception e) {
						;
					}

					cart.addItem();
					cart.addItem();
					cart.addItem();
					
					System.out.println("Number of items in the cart: "+cart.getItems());
				}
				catch (NoSuchEJBException nsee) {
					System.out.println("Cart was already removed during iteration "+i);
				}
			}
		} 
		catch (NamingException e) {
			e.printStackTrace();
		}
	}
}

⌨️ 快捷键说明

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