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

📄 sessionstateclient.java

📁 使用J2EE编写的网上商店系统
💻 JAVA
字号:
/*
 * Created on 1999-5-17
 */
package testClient;

import java.rmi.RemoteException;
import java.util.Hashtable;

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

/**
 * @author 28-9
 *
 * TODO To change the template for this generated type comment go to
 * Window - Preferences - Java - Code Generation - Code and Comments
 */
public class SessionStateClient {
	private state.StoreAccessStateHome getHome() throws NamingException {
		return (state.StoreAccessStateHome) getContext().lookup(
				state.StoreAccessStateHome.JNDI_NAME);
	}
	private InitialContext getContext() throws NamingException {
		Hashtable props = new Hashtable();
		props.put(InitialContext.INITIAL_CONTEXT_FACTORY,
				"org.jnp.interfaces.NamingContextFactory");
		props.put(InitialContext.PROVIDER_URL, "jnp://127.0.0.1:1099");
		// This establishes the security for authorization/authentication
		// props.put(InitialContext.SECURITY_PRINCIPAL,"username");
		// props.put(InitialContext.SECURITY_CREDENTIALS,"password");
		InitialContext initialContext = new InitialContext(props);
		return initialContext;
	}
	public void testBean() {
		String userID=null;
		try {
			state.StoreAccessState myBean = getHome().create(userID);
			System.out.println("Request from client: ");
			userID=myBean.loginUser("danny", "swdandy");
			System.out.println("Reply from Server: Your userid is "+userID);
			
			myBean.setUserID(userID);
			System.out.println("Going to Sleep for 1 min.................");
			
			Thread.sleep(60000);//sleep from 1 minute.
			System.out.println("Reply from bean after 1 min "+myBean.getUserID());
			
			System.out.println("Again going to sleep for 3 min..............");
			Thread.sleep(180000); //sleep for 3 minute
			System.out.println("Resuming after 3 mins..............");
			
			System.out.println("Reply from bean after 3 mins "+myBean.getUserID());
			//--------------------------------------
			//This is the place you make your calls.
			//System.out.println(myBean.callYourMethod());
		} catch (RemoteException e) {
			e.printStackTrace();
		} catch (CreateException e) {
			e.printStackTrace();
		} catch (NamingException e) {
			e.printStackTrace();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	public static void main(String[] args) {
		SessionStateClient test = new SessionStateClient();
		test.testBean();
	}
}

⌨️ 快捷键说明

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