⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 3.mht

📁 Enterprise Java Bean的PPT文档,很好的东西.
💻 MHT
📖 第 1 页 / 共 5 页
字号:
From: <由 Microsoft Internet Explorer 5 保存>
Subject: Tutorial for building J2EE Applications using JBOSS and ECLIPSE
Date: Thu, 16 Dec 2004 14:35:13 +0800
MIME-Version: 1.0
Content-Type: multipart/related;
	boundary="----=_NextPart_000_00A2_01C4E37C.7424B8B0";
	type="text/html"
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409

This is a multi-part message in MIME format.

------=_NextPart_000_00A2_01C4E37C.7424B8B0
Content-Type: text/html;
	charset="Windows-1252"
Content-Transfer-Encoding: quoted-printable
Content-Location: file://F:\java_trainning\1206\tuscejb\3.htm

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!-- saved from =
url=3D(0047)http://www.tusc.com.au/tutorial/html/chap3.html =
--><HTML><HEAD><TITLE>Tutorial for building J2EE Applications using =
JBOSS and ECLIPSE</TITLE>
<META http-equiv=3DCONTENT-TYPE content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR>
<META content=3D"Glen McCallum and Vishal Sharma" name=3DAUTHOR>
<META content=3D20030729;9513900 name=3DCREATED>
<META content=3DVishal name=3DCHANGEDBY>
<META content=3D20031118;15354000 name=3DCHANGED>
<META=20
content=3D"Tutorial for building J2EE Applications using Eclipse, =
Lomboz, Jboss and Xdoclet."=20
name=3DDESCRIPTION>
<META=20
content=3D"J2EE, Traininig,Tutorial, J2EE, Lomboz, Eclipse, Jboss, =
Xdoclet, J2EE Patterns, EJB, Servlets, JSP, BMP, CMP, Session, =
Configuration, DAO"=20
name=3DKEYWORDS>
<META content=3D"14 days" name=3Drevisit-after><!-- Meta tags --><!-- =
Copyright =A9 2003 TUSC. All rights reserved.--><!--- Header --></HEAD>
<BODY lang=3Den-US dir=3Dltr>
<FORM name=3DsearchForm action=3D../../../../search/index.php =
method=3Dpost>
<TABLE style=3D"PAGE-BREAK-BEFORE: always" cellSpacing=3D0 =
cellPadding=3D4 width=3D957=20
bgColor=3D#0a6a91 border=3D0>
  <COLGROUP>
  <COL width=3D154>
  <COL width=3D276>
  <COL width=3D21>
  <COL width=3D43>
  <COL width=3D119>
  <COL width=3D31>
  <COL width=3D50>
  <COL width=3D178>
  <COL width=3D14>
  <TBODY>
  <TR>
    <TD vAlign=3Dtop width=3D178>
      <P><A href=3D"http://www.logec.com/"><IMG height=3D125=20
      alt=3D"LOGEC's Event Correlation"=20
      src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/logec.gif" =
width=3D200=20
      align=3Dbottom border=3D0 name=3DGraphic57></A> </P></TD>
    <TD vAlign=3Dtop width=3D276>
      <P><IMG height=3D73 alt=3D"Reliable, On-Time Delivery."=20
      =
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/reliable.gif"=20
      width=3D268 align=3Dbottom border=3D0 name=3DGraphic2><!--search =
table --></P></TD>
    <TD width=3D21></TD>
    <TD width=3D43>
      <P><IMG height=3D9 alt=3DSearch=20
      src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/search.gif" =
width=3D41=20
      align=3Dbottom border=3D0 name=3DGraphic3></P></TD>
    <TD width=3D119>
      <P><INPUT maxLength=3D50 size=3D12 name=3DKEYWORD></P></TD>
    <TD width=3D31>
      <P><INPUT type=3Dimage height=3D18 width=3D29=20
      src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/go.gif" =
align=3Dbottom=20
      name=3Dgo><INPUT type=3Dhidden value=3DY =
name=3DSECTION_ALL></P></TD>
    <TD vAlign=3Dtop width=3D50>
      <P><IMG height=3D73 alt=3DSpacer=20
      src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/invis.gif" =
width=3D50=20
      align=3Dbottom border=3D0 name=3DGraphic5></P></TD>
    <TD vAlign=3Dtop width=3D154>
      <P><A=20
      =
href=3D"http://www.tusc.com.au/news_events/event_details.php?id=3D44"><IM=
G=20
      height=3D125 alt=3DTUSC=20
      =
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/tuscJ2eeLogo.gif"=20
      width=3D149 align=3Dbottom border=3D0 =
name=3DGraphic1></A></P></TD>
    <TD width=3D14>
      <P><IMG height=3D10 alt=3Dspacer=20
      src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/invis.gif" =
width=3D14=20
      align=3Dbottom border=3D0 name=3DGraphic58> =
</P></TD></TR></TBODY></TABLE></FORM>
<P><!--- Header finished --><BR><BR></P>
<H2 align=3Dcenter>Tutorial for building J2EE Applications using JBOSS =
and ECLIPSE=20
<IMG height=3D2 =
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/redrulr5.gif"=20
width=3D775 align=3Dmiddle border=3D0 name=3DGraphic1></H2>
<P><BR><BR></P>
<H1>Chapter 3. </H1>
<P><IMG height=3D2=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/blurulr6.gif" =
width=3D785=20
align=3Dmiddle border=3D0 name=3DGraphic2></P>
<H2>Creating a Stateless Session Bean</H2>
<P>This chapter covers how to create a stateless session EJB component. =
This=20
bean will be responsible for authenticating the user by communicating =
with the=20
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. </P>
<P><BR><BR></P>
<P><IMG height=3D86=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/J2EECaseStudyFlowDi=
agram.png"=20
width=3D607 align=3Dleft border=3D0 name=3DGraphic26><BR =
clear=3Dleft><BR><BR></P>
<P>All customers, supplier and manager of MyStore have been assigned a =
unique=20
username and userid to access services of MyStore, but in order to =
access these=20
services all these entities have to first login into the system =
(MyStore). The=20
method for authentication is named <B>loginUser</B>, which takes <B>two =
String=20
parameters, username and password and returns the userID if =
authentication is=20
successful. </B></P>
<P><FONT color=3D#800000><I>Note : This method loginUser is a business =
method,=20
normally business methods carry out operations or processing on values =
EJB=20
components. From clients perspective, clients can see only business =
methods and=20
invoke them on bean.</I></FONT></P>
<H3>Tasks :</H3>
<OL>
  <LI>
  <P>Create a J2EE project named MyStore.</P>
  <LI>
  <P>Create a Stateless Session Bean named StoreAccess.</P>
  <LI>
  <P>Add a business method in bean named loginUser with the following=20
  signature</P>
  <P><B>public String loginUser (String username, String =
password)</B></P>
  <LI>
  <P>Create a DAO named StoreAccessDAOImpl under package =
au.com.tusc.dao.=20
  Generate the DAO interface.</P>
  <LI>
  <P>Implement the method named loginUser, generated in DAO interface, =
in=20
  StoreAccessDAOImpl. Method signature is </P>
  <P><B>public String loginUser (String username, String password) =
</B></P>
  <LI>
  <P>Add callback methods and implement them.</P>
  <LI>
  <P>Deploy StoreAccess bean.</P>
  <LI>
  <P>Create your test client named SessionClient under package=20
  au.com.tusc.client.</P>
  <LI>
  <P>Run your client and test the bean.</P></LI></OL>
<H3><B>Create J2EE Project :</B></H3>
<P>Now, lets start to write our first component of this tutorial.</P>
<P><B>Go to File &gt; New &gt; LombozJ2EE Project, project creation =
wizard will=20
pop up.</B></P>
<P><B>Insert Project Name MyStore &gt; Next .</B></P>
<P><B>Under Java Settings Check source, should be MyStore/src , =
libraries=20
pointing to $JAVA_HOME &gt; Go Next as shown in fig below. </B></P>
<P align=3Dleft><FONT color=3D#800000><I>Note: This step is shown in =
chapter1, as=20
there is a bug in eclipse 2.1, so its important that you check your =
library=20
settings are right.</I></FONT></P>
<P><IMG height=3D527=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/CreateJ2eeProjectLi=
braries.png"=20
width=3D605 align=3Dleft border=3D0 name=3DGraphic53><BR =
clear=3Dleft><BR><BR></P>
<P><B>Under Create J2EE Module, select Web Modules tab &gt; Add.., enter =
Module=20
name as OnlineStore &gt; OK as shown in figure below.</B></P>
<P><IMG height=3D548=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/CreateJ2eeAddWebMod=
ule.png"=20
width=3D713 align=3Dleft border=3D0 name=3DGraphic52><BR =
clear=3Dleft><BR><BR></P>
<P><B>Under Create J2EE Module, select EJB Modules tab &gt; Add.., enter =
Module=20
name as MyStoreMgr &gt; OK .</B></P>
<P><B>Under Create J2EE Module, select Targeted Servers tab &gt; Select =
JBOSS=20
3.2.1 ALL &gt; Add.. &gt; Finish.</B></P>
<P><BR><BR></P>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><B>Create Stateless =
Bean=20
:</B></H3>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P><B>Go To Package Explorer &gt; Expand Mystore (project) node &gt; =
select src,=20
right click and menu will pop up.</B></P>
<P><B>On pop up menu &gt; New &gt; Lomboz EJB Creation Wizard.</B></P>
<P><B>Enter package name au.com.tusc.session, bean name StoreAccess and =
select=20
bean type as stateless &gt; Finish.</B></P>
<P><B>This will create a package named au.com.tusc.session under src and =

StoreAccessBean under that package as shown in the figure below.</B></P>
<P align=3Dleft><IMG height=3D489=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/SessionBeanView.png=
"=20
width=3D922 align=3Dleft border=3D0 name=3DGraphic54><BR =
clear=3Dleft><BR><BR></P>
<P align=3Dleft><B>As we can see from the figure below it has created a =
class=20
level tag @ejb.bean, which has assigned the bean type, name and its JNDI =
name=20
which will be generated in Home interface. This tag will also generate=20
deployment descriptors in ejb-jar.xml and jboss.xml file as well once =
you=20
generate your EJB classes, which is covered later on in this =
chapter.</B></P>
<P align=3Dleft><IMG height=3D195=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/StoreAccessBeanJndi=
Descp.png"=20
width=3D217 align=3Dleft border=3D0 name=3DGraphic43><BR =
clear=3Dleft><BR><BR></P>
<P><FONT color=3D#800000><I>Note: It will generate the bean name, =
jndi-name and=20
type of bean in the file. Also, the name of file is appended with word =
'Bean' as=20
you gave the name of the bean as StoreAccess only. Again, be careful =
with naming=20
conventions, specifying the bean name only in the wizard without adding =
the word=20
'Bean' to the name as the wizard appends that for you. </I></FONT></P>
<P><FONT color=3D#800000><I>Expand MyStoreMgr/META-INF node under =
Package=20
Explorer. You will find there are seven files which are generated by =
Lomboz=20
using Xdoclet as shown in the figure below. </I></FONT></P>
<P align=3Dleft><IMG height=3D514=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/SessionBeanGenearte=
dDescView.png"=20
width=3D311 align=3Dleft border=3D0 name=3DGraphic3><BR =
clear=3Dleft><BR><BR></P>
<P>Now we are going to generate all the interfaces including Home, =
Remote, DAO=20
and other helper classes. We will explain why later on, but for the time =
being=20
just follow the steps.</P>
<P>But before we get too excited, there are a few concepts to cover =
here.</P>
<P><B>Go to MyStoreMgr/META-INF &gt; select and open =
ejbGenerate.xml.</B></P>
<P><FONT color=3D#800000><I>Note: Lomboz uses this file to generate =
required=20

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -