隨筆-60  評(píng)論-117  文章-0  trackbacks-0

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

          ejb工程的創(chuàng)建:
          基本上直接點(diǎn)擊“下一步”即可。但要注意看

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

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

           

          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) + "日前です。");
           }

          }

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

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

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

          只有注冊(cè)用戶登錄后才能發(fā)表評(píng)論。


          網(wǎng)站導(dǎo)航:
           
          主站蜘蛛池模板: 庆安县| 平遥县| 攀枝花市| 都安| 城市| 高雄市| 容城县| 仁怀市| 曲阜市| 晋州市| 延庆县| 西乌珠穆沁旗| 类乌齐县| 阿合奇县| 甘德县| 芦山县| 衡南县| 榆树市| 府谷县| 天全县| 临漳县| 师宗县| 建昌县| 巩义市| 昌江| 繁昌县| 太仆寺旗| 绵竹市| 黎城县| 灵璧县| 芒康县| 景洪市| 万全县| 孝昌县| 治多县| 贵州省| 长汀县| 胶南市| 宁津县| 连平县| 大竹县|