隨筆-60  評論-117  文章-0  trackbacks-0

          相關運行環境:
          1.jdk150_04
          2.eclipse3.2
          3.weblogic server9.2
          4.wtp-R-1.5.4-200705021353(里面包含ejb插件)
          5.xdoclet-1.2.3

          ejb工程的創建:
          基本上直接點擊“下一步”即可。但要注意看

          建完的工程是否含有以下libraries:
          1.jre system libraries
          2.generic bea weblogic server v9.2
          3.weblogic.jar
          4.ear libraries
          這樣系統會自動生成配置文件。

          實例:
          實現功能:
          從服務器端取系統時間,與客戶端時間求時間間隔。
          服務器端代碼:
          bean里的foo()(其他按照自動生成的即可)
           public Calendar foo(String param) {
            Calendar calCurrent = Calendar.getInstance();
            Date timeCurrent=new Date();
            calCurrent.setTime(timeCurrent);
            return calCurrent;
           }
          客戶端代碼:
          創建一個新類:

           

          package test;

          import java.io.BufferedReader;
          import java.io.IOException;
          import java.io.InputStreamReader;
          import java.rmi.RemoteException;
          import java.util.Calendar;
          import java.util.Properties;

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

          public class TestClient {

           /**
            * @param args
            */
           public static void main(String[] args) {
            // TODO Auto-generated method stub
            String url = "t3://localhost:7001";

            // Hashtable env = new Hashtable();
            // env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");
            // env.put(Context.PROVIDER_URL, url);
            Properties properties = new Properties();
            properties.put(Context.INITIAL_CONTEXT_FACTORY,
              "weblogic.jndi.WLInitialContextFactory");
            properties.put(Context.PROVIDER_URL, url);
            int dayCurrent = 0;
            Test my = null;
            try {
             my = TestUtil.getHome(properties).create();
            } catch (RemoteException e1) {
             // TODO Auto-generated catch block
             e1.printStackTrace();
            } catch (CreateException e1) {
             // TODO Auto-generated catch block
             e1.printStackTrace();
            } catch (NamingException e1) {
             // TODO Auto-generated catch block
             e1.printStackTrace();
            }
            try {
             dayCurrent = my.foo("").get(Calendar.DAY_OF_YEAR);
            } catch (Exception e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            }
            Calendar birthday = Calendar.getInstance();
            int year = 0;
            int month = 0;
            int day = 0;
            System.out.println("誕生日を入力してください:");
            BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
            try {
             System.out.print("年:");
             year = Integer.parseInt(in.readLine());
             System.in.skip(6);
             System.out.print("月:");
             month = Integer.parseInt(in.readLine())-1;
             System.in.skip(6);
             System.out.print("日:");
             day = Integer.parseInt(in.readLine());

            } catch (IOException e) {
             System.out.print("フォーマットが違います。");
            }
            birthday.set(year, month, day);
            int yearCount=0;
            int dayBirthday = birthday.get(Calendar.DAY_OF_YEAR);
            int dayCount = dayBirthday - dayCurrent;
            try {
             yearCount=my.foo("").get(Calendar.YEAR)-birthday.get(Calendar.YEAR);
            } catch (RemoteException e) {
             // TODO Auto-generated catch block
             e.printStackTrace();
            }
            
            if (dayCount >= 0)
             System.out.println("あなたの"+yearCount+"才誕生日は" + dayCount + "日後です。");
            else
             System.out.println("あなたの"+yearCount+"才誕生日は" + Math.abs(dayCount) + "日前です。");
           }

          }

          運行結果:
          誕生日を入力してください:
          年:1986
          月:10
          日:12
          あなたの21才誕生日は24日前です。

          posted on 2007-11-05 11:26 靜兒 閱讀(1061) 評論(7)  編輯  收藏

          評論:
          # re: 以weblogic為服務器,運行ejb程序 2007-11-05 11:46 | 千里冰封
          怎么輸出了日語?  回復  更多評論
            
          # re: 以weblogic為服務器,運行ejb程序 2007-11-05 12:05 | 靜兒
          呵呵,我的編碼方式不支持中文。@千里冰封
            回復  更多評論
            
          # re: 以weblogic為服務器,運行ejb程序[未登錄] 2007-11-05 16:08 | Tony
          我發現好多程序員都東渡到日本討生活了。我想樓主也是其中一員吧。  回復  更多評論
            
          # re: 以weblogic為服務器,運行ejb程序 2007-11-05 16:19 | 靜兒
          呵呵,那倒沒有。我做的是對日外包,所以用日文操作系統。@Tony
            回復  更多評論
            
          # re: 以weblogic為服務器,運行ejb程序 2007-11-06 09:29 | BeanSoft
          你這個寫的也太.... 順便說一下 Weblogic 9 Bug 多多, Weblogic 10 開始正式支持 Java EE 5.  回復  更多評論
            
          # re: 以weblogic為服務器,運行ejb程序 2007-11-06 10:23 | 靜兒
          哦,謝謝。現在在項目中,沒時間寫的詳細,或者編寫稍微復雜的代碼。@BeanSoft
            回復  更多評論
            
          # re: 以weblogic為服務器,運行ejb程序 2009-09-24 15:02 | 達飛Plus
          學習了  回復  更多評論
            

          只有注冊用戶登錄后才能發表評論。


          網站導航:
           
          主站蜘蛛池模板: 太湖县| 尉氏县| 昔阳县| 仁化县| 拜泉县| 南投县| 阳城县| 朝阳市| 青冈县| 南城县| 濮阳县| 临海市| 泗阳县| 朝阳市| 新宾| 团风县| 仙桃市| 肇州县| 华宁县| 武宁县| 甘泉县| 义马市| 察哈| 古田县| 本溪| 江都市| 延津县| 霸州市| 梨树县| 三台县| 莎车县| 察雅县| 城市| 墨江| 卓资县| 沙河市| 大田县| 古丈县| 宁安市| 乌兰察布市| 泌阳县|