holidaycalendartestclient1.java
来自「100多M的J2EE培训内容」· Java 代码 · 共 76 行
JAVA
76 行
package meetings;import com.cwj.meetings.*;import javax.naming.*;import java.util.Properties;import javax.rmi.PortableRemoteObject;public class HolidayCalendarTestClient1 extends Object { private HolidayCalendarHome holidayCalendarHome = null; //Construct the EJB test client public HolidayCalendarTestClient1() { initialize(); } public void initialize() { try { //get naming context Context context = getInitialContext(); //look up jndi name Object ref = context.lookup("Holiday/HolidayCalendar"); //look up jndi name and cast to Home interface holidayCalendarHome = (HolidayCalendarHome) PortableRemoteObject.narrow(ref, HolidayCalendarHome.class); HolidayCalendar hcal=holidayCalendarHome.create(); if(hcal.isCompanyHoliday(new java.util.Date())) { System.out.println("Today is a holiday :-)"); } else { System.out.println("Today is a working day :-("); } } catch(Exception e) { e.printStackTrace(); } } private Context getInitialContext() throws Exception { String url = "t3://127.0.0.1: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; } } //---------------------------------------------------------------------------- // Utility Methods //---------------------------------------------------------------------------- public HolidayCalendarHome getHome() { return holidayCalendarHome; } //Main method public static void main(String[] args) { HolidayCalendarTestClient1 client = new HolidayCalendarTestClient1(); // Use the getHome() method of the client object to call Home interface // methods that will return a Remote interface reference. Then // use that Remote interface reference to access the EJB. }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?