Tutorial for building J2EE Applications using…
2008-02-23 09:44:50来源:互联网 阅读 ()
Chapter 3.
Creating a Stateless Session Bean
This chapter covers how to create a stateless session EJB component. This bean will be responsible for authenticating the user by communicating with the database using Data Access Object (DAO) which encapsulates Java Database Connectivity (JDBC) code. A DAO has all attributes (fields) and behavior (methods) corresponding to the bean it is being used for.
All customers, supplier and manager of MyStore have been assigned a unique username and userid to access services of MyStore, but in order to access these services all these entities have to first login into the system (MyStore). The method for authentication is named loginUser, which takes two String parameters, username and password and returns the userID if authentication is successful.
Note : This method loginUser is a business method, normally business methods carry out operations or processing on values EJB components. From clients perspective, clients can see only business methods and invoke them on bean.
Tasks :
Create a J2EE project named MyStore.
Create a Stateless Session Bean named StoreAccess.
Add a business method in bean named loginUser with the following signature
public String loginUser (String username, String password)
Create a DAO named StoreAccessDAOImpl under package au.com.tusc.dao. Generate the DAO interface.
Implement the method named loginUser, generated in DAO interface, in StoreAccessDAOImpl. Method signature is
public String loginUser (String username, String password)
Add callback methods and implement them.
Deploy StoreAccess bean.
Create your test client named SessionClient under package au.com.tusc.client.
Run your client and test the bean.
Create J2EE Project :
Now, lets start to write our first component of this tutorial.
Go to File > New > LombozJ2EE Project, project creation wizard will pop up.
Insert Project Name MyStore > Next .
Under Java Settings Check source, should be MyStore/src , libraries pointing to $JAVA_HOME > Go Next as shown in fig below.
Note: This step is shown in chapter1, as there is a bug in Eclipse 2.1, so its important that you check your library settings are right.
Under Create J2EE Module, select Web Modules tab > Add.., enter Module name as OnlineStore > OK as shown in figure below.
Under Create J2EE Module, select EJB Modules tab > Add.., enter Module name as MyStoreMgr > OK .
Under Create J2EE Module, select Targeted Servers tab > Select JBOSS 3.2.1 ALL > Add.. > Finish.
Create Stateless Bean :
Go To Package Explorer > Expand Mystore (project) node > select src, right click and menu will pop up.
On pop up menu > New > Lomboz EJB Creation Wizard.
Enter package name au.com.tusc.session, bean name StoreAccess and select bean type as stateless > Finish.
This will create a package named au.com.tusc.session under src and StoreAccessBean under that package as shown in the figure below.
As we can see from the figure below it has created a class level tag @ejb.bean, which has assigned the bean type, name and its JNDI name which will be generated in Home interface. This tag will also generate deployment descriptors in ejb-jar.XML and jboss.xml file as well once you generate your EJB classes, which is covered later on in this chapter.
Note: It will generate the bean name, jndi-name and type of bean in the file. Also, the name of file is appended with word 'Bean' as you gave the name of the bean as StoreAccess only. Again, be careful with naming conventions, specifying the bean name only in the wizard without adding the word 'Bean' to the name as the wizard appends that for you.
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash