java.beans.transient_建立你的第一个无状态会话Bean--HelloWorld之二

这里是 DemoBean 企业JavaBeans DemoBean.java 的源代码:

/**

* DemoBean -- This is implemented by the EnterPrise

* Bean author This class must extend

* javax.ejb.SessionBean and implement

* the methods in this interface as well as providing

* the implementation of the business methods.

*

*/

package ejb.demo;

import javax.ejb.*;

import java.io.Serializable;

import java.util.*;

import java.rmi.*;

public class DemoBean implements SessionBean {

static final boolean verbose = true;

private transient SessionContext ctx;

private transient Properties props;

// Implement the methods in the SessionBean

// interface

public void ejbActivate() {

if (verbose)

System.out.println("ejbActivate called");

}

public void ejbRemove() {

if (verbose)

System.out.println("ejbRemove called");

}

public void ejbPassivate() {

if (verbose)

System.out.println("ejbPassivate called");

}

/**

* Sets the session context.

*

* @param SessionContext

*/

public void setSessionContext(SessionContext ctx) {

if (verbose)

System.out.println("setSessionContext called");

this.ctx = ctx;

props = ctx.getEnvironment();

}

/**

* This method corresponds to the create method in

* the home interface DemoHome.java.

* The parameter sets of the two methods are

* identical. When the client calls

* DemoHome.create(), the container allocates an

* instance of the EJBean and calls ejbCreate().

*/

public void ejbCreate () {

if (verbose)

System.out.println("ejbCreate called");

}

/**

* **** HERE IS THE BUSINESS LOGIC *****

* Do the demoSelect() but don't even go to

* the database in this eg but instead just

* return a String.

* The really BIG thing to notice here is that

* this is the only code we have invented at all

* the rest of the code has been declarations

* or simply implementing methods which are

* part of the EJB interfaces and in this example

* are not even used.

*/

public String demoSelect()

throws RemoteException

{

return("hello world");

}

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值