网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.Java的基本数据类型与流.
.EJB 3.0的三大类型详解.
.关于J2ME网络应用程序的性能探讨.
.Java实现POP3服务器.
.Velocity中的变量问题的解决方法.
.如何设计出具有GUI特色的纯JAVA程.
.Struts源码研究 - logic-Iterato.
.世界robocode机器人的四大运动方.
.一个在程序中实现plugin机制的简.
.如何轻松实现JavaBeans到XML的相.
.Java EJB容器的存取和实现.
.Java Web Start入门基础教程.
.连接PHP和 Java -- PHP/Java Bri.
.JAVA中jar文件的编写和应用.
.使用hibernate扩展工具hbm2java根.
.在MIDP1.0中简单模拟图片翻转功能.
.Quartz与Hibernate数据库连接的结.
.全程指导Linux下JAVA环境配置.
.EJB核心技术及其应用.
.在构建器里调用构建器.

JBoss技术支持文档

发表日期:2008-1-5


1、下载例子源程序

  所有例子的源代码可以直接从 www.jboss.org进行下载。下载完后放在一个目录下。下载网址:http://www.jboss.org/docs/manual/files/documentation-example.zip

  1.1 建立 BEAN

  此节主要是建立一个简单的EJB,可以查看代码,这个“Interest”例子,是一个简单无状态的会话EJB。它的目的是根据说明的利息率,来对借的所有钱计算利息。实际上在整个包代码中只有一行功能。

  1.2 回顾EJBs

  在我们查看代码之前,我们先对EJB进行复习一下。在EJB最小类型,也必须有三个类:remote interface, home interface和bean实现类。

  remote interface是会把EJB中方法提供给外边世界,让外边的代码来进行调用,在这个例子中类名称是org.jboss.interest.Interrest。

  home interface是治理remote interface类的类。包括建立、删除等操作。在这个例子中类名称是org.jboss.interest.InterrestHome。

  bean实现类提供home interface和remote interface所有方法的实现。在这个例子中类名称是org.jboss.interest.InterrestBean。

  当然一个Bean可能还包括其他类,甚至其他包。但是必须有此三个类,其他类是在此三个类之上建立的。所有类被打包进一个JAR文件,此文件是用一个目录结构来反映出包的层次关系。在此例子中所有类都打包在org.jboss.interest包中,所以他们需要在目录org/jboss/interest/下。

  在包含所有类的jar文件建立之前,必须有一个META-INF目录。此目录存放了部署描述符(通常叫“ejb-jar.XML”),和可选的其他XML文件。这些文件告诉服务器关于应用明确服务信息。对于JBoss 来讲,文件名必须叫“jboss.xml”。

  创建jar文件后部署到JBoss Server上。在客户端你需要一个jndi.properties文件,此文件告诉你的客户端程序从哪里初始化查找JNDI 命名服务。从这个服务,客户端将查找到Interest bean,并且返回bean的home interface。home interface用来得到bean的一个remote interface。它可以用远程接口来访问bean提供的商业方法。

  1.3 EJB类

  我们需要三个类:remote interface, home interface 和bean实现类。remote interface远程接口类,文件名Interest.Java。代码如下:

package org.jboss.docs.interest;
import javax.ejb.EJBObject;
import java.rmi.RemoteException;
/**
This interface defines the `Remote' interface for the `Interest' EJB. Its
single method is the only method eXPosed to the outside world. The class
InterestBean implements the method.
*/
public interface Interest extends EJBObject
{
/** Calulates the compound interest on the sum `principle', with interest rate per period `rate' over `periods' time periods. This method also prints a message to standard output; this is picked up by the EJB server and logged. In this way we can demonstrate that the method is actually being executed on the server, rather than the client. */

public double calculateCompoundInterest(double principle, double rate, double periods) throws RemoteException;

}

  远程接口只有一个商业方法calculateCompoundInterest。Home interface 文件名InterestHome.java。代码如下:

package org.jboss.docs.interest;
import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;

/**
This interface defines the 'home' interface for the 'Interest' EJB.
*/
public interface InterestHome extends EJBHome
{
/** Creates an instance of the `InterestBean' class on the server, and returns a remote reference to an Interest interface on the client. */

上一篇:错误的堆大小产生的“堆问题” 人气:528
下一篇:Java理论与实践:哈希 人气:699
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐