chapter 4.
creating a stateful session bean 【程序编程相关:基于J2EE的开发的一些经验】
【推荐阅读:J2me开发心得-数组的使用】
well try something a little less ambitious for the time being! this bean is similar to the storeaccess bean created in the previous chapter except that it will store the userid of the client, after authentication is successful. 【扩展信息:Java语言编码规范(Java Code】this chapter covers how to create a stateful session ejb component. unlike stateless beans, stateful bean instances are associated with a particular client session and can therefore maintain information useful during the lifetime of that session. a classic and familiar example of this in a web e-commerce context is that of a shopping cart.note : this bean will not be used further in tutorial, as this chapter demonstrates how stateful beans are created.
tasks :
create a stateful session bean named storeaccessstate.
add a business method in the bean named loginuser with the signature
public string loginuser (string username, string password)
add a call back method ejbcreate with the signature
public void ejbcreate (string userid)
generate the dao interface.
access the dao named storeaccesdaoimpl under package au.com.tusc.dao, created and implemented in the previous chapter. this dao has a method named loginuser, called by loginuser in the bean with the signature
public string loginuser (string username, string password)
deploy the storeaccessstate bean.
create your test client named sessionstateclient under package au.com.tusc.client.
run your client and test the bean.
create stateless bean :
go to package explorer > expand mystore (project) node > select src, right click and a menu will pop up.
on pop up menu > new > lomboz ejb creation wizard.
enter the package name au.com.tusc.sessionstate, bean name storeaccessstate and select bean type as stateful > finish.
this will create package named au.com.tusc.sessionstate under src and storeaccessstatebean under that package as shown below.
... 下一页