随笔-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 静儿 阅读(1046) 评论(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
学习了  回复  更多评论
  

只有注册用户登录后才能发表评论。


网站导航: