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

📄 4.mht

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

This is a multi-part message in MIME format.

------=_NextPart_000_0166_01C4DAC1.712722B0
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable
Content-Location: http://www.tusc.com.au/tutorial/html/chap4.html

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<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.1479" 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=3D20040312;14394700 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=3D154>
      <P><A href=3D"http://www.tusc.com.au./contact_us.php"><IMG =
height=3D125=20
      alt=3DTUSC=20
      =
src=3D"http://www.tusc.com.au/tutorial/images/header/tuscJ2eeLogo.gif"=20
      width=3D149 align=3Dbottom border=3D0 =
name=3DGraphic1></A></P></TD>
    <TD vAlign=3Dtop width=3D276>
      <P><IMG height=3D73 alt=3D"Reliable, On-Time Delivery."=20
      src=3D"http://www.tusc.com.au/tutorial/images/header/reliable.gif" =
width=3D268=20
      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"http://www.tusc.com.au/tutorial/images/elements/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"http://www.tusc.com.au/tutorial/images/btns/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"http://www.tusc.com.au/tutorial/images/invis.gif" =
width=3D50=20
      align=3Dbottom border=3D0 name=3DGraphic5></P></TD>
    <TD vAlign=3Dtop width=3D154>
      <P><A href=3D"http://www.tusc.com.au./contact_us.php"><IMG =
height=3D125=20
      alt=3DTUSC=20
      =
src=3D"http://www.tusc.com.au/tutorial/images/header/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"http://www.tusc.com.au/tutorial/images/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"http://www.tusc.com.au/tutorial/images/redrulr5.gif"=20
width=3D775 align=3Dmiddle border=3D0 name=3DGraphic1></H2>
<P><BR><BR></P>
<H1>Chapter 4. </H1>
<P><IMG height=3D2 =
src=3D"http://www.tusc.com.au/tutorial/images/blurulr6.gif"=20
width=3D785 align=3Dmiddle border=3D0 name=3DGraphic2></P>
<H2>Creating a Stateful Session Bean</H2>
<P align=3Dleft>This chapter covers how to create a stateful session EJB =

component. Unlike stateless beans, stateful bean instances are =
associated with a=20
particular client session and can therefore maintain information useful =
during=20
the lifetime of that session. A classic and familiar example of this in =
a web=20
e-commerce context is that of a shopping cart.</P>
<P align=3Dleft>We'll try something a little less ambitious for the time =
being!=20
This bean is similar to the StoreAccess Bean created in the previous =
chapter=20
except that it will store the userID of the client, after authentication =
is=20
successful. </P>
<P><IMG height=3D92=20
src=3D"http://www.tusc.com.au/tutorial/images/chap4/StoreAccessState.png"=
=20
width=3D439 align=3Dleft border=3D0 name=3DGraphic21><BR =
clear=3Dleft><BR><BR></P>
<P><FONT color=3D#800000><I>Note : This bean will not be used further in =
tutorial,=20
as this chapter demonstrates how stateful beans are created. =
</I></FONT></P>
<H3>Tasks :</H3>
<OL>
  <LI>
  <P>Create a Stateful Session Bean named StoreAccessState.</P>
  <LI>
  <P>Add a business method in the bean named loginUser with the =
signature</P>
  <P><B>public String loginUser (String username, String =
password)</B></P>
  <LI>
  <P>Add a call back method ejbCreate with the signature</P>
  <P><B>public void ejbCreate (String userID)</B></P>
  <LI>
  <P>Generate the DAO interface.</P>
  <LI>
  <P>Access the DAO named StoreAccesDAOImpl under package =
au.com.tusc.dao,=20
  created and implemented in the previous chapter. This DAO has a method =
named=20
  loginUser, called by loginUser in the bean with the signature </P>
  <P><B>public String loginUser (String username, String =
password)</B></P>
  <LI>
  <P>Deploy the StoreAccessState bean.</P>
  <LI>
  <P>Create your test client named SessionStateClient under package=20
  au.com.tusc.client.</P>
  <LI>
  <P>Run your client and test the bean.</P></LI></OL>
<H3><BR><BR></H3>
<H3><B>Create Stateless Bean :</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 a menu will pop up.</B></P>
<P><B>On pop up menu &gt; New &gt; Lomboz EJB Creation Wizard.</B></P>
<P><B>Enter the package name au.com.tusc.sessionState, bean name=20
StoreAccessState and select bean type as stateful &gt; Finish.</B></P>
<P><B>This will create package named au.com.tusc.sessionState under src =
and=20
StoreAccessStateBean under that package as shown below.</B></P>
<P align=3Dleft><IMG height=3D218=20
src=3D"http://www.tusc.com.au/tutorial/images/chap4/StaoreAccessState.png=
"=20
width=3D570 align=3Dleft border=3D0 name=3DGraphic43><BR =
clear=3Dleft><B>As we can see=20
from the figure above it has created a class level tag @ejb.bean, which =
has=20
assigned the bean type, name and its JNDI name which will be generated =
in the=20
Home interface. This tag will also generate deployment descriptors in=20
ejb-jar.xml and jboss.xml file as well once you generate your EJB =
classes, which=20
is covered later on in this chapter</B>.</P>
<P align=3Dleft><FONT color=3D#800000><I>Note: It will generate the bean =
name,=20
jndi-name and type of bean in file. Also, the name of file is appended =
with word=20
'Bean' as you gave the name of the bean as StoreAccess only. So be =
careful with=20
your naming convention, as you only need specify the bean name in the =
wizard=20
(ie. without a 'Bean' suffix as the wizard will append that for you).=20
</I></FONT></P>
<P><IMG height=3D514=20
src=3D"http://www.tusc.com.au/tutorial/images/chap3/SessionBeanGeneartedD=
escView.png"=20
width=3D311 align=3Dleft border=3D0 name=3DGraphic3><BR =
clear=3Dleft><BR><BR></P>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><B>Create DAO =
Interface=20
:</B></H3>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P>Since we are going to use a DAO to access the database for this =
Stateful=20
Bean, we will use the StoreAccesDAOImpl class which was created and =
implemented=20
in the previous chapter. This will provide the implementation for the =
generated=20
DAO interface.</P>
<P><B>Now go to your Bean class and declare this tag at class level =
(i:e; at=20
top), as described below to generate the DAO =
interface.</B></P><PRE><FONT color=3D#3f5fbf>   <FONT size=3D3><FONT =
face=3DSans>@ejb.dao =
class=3D"au.com.tusc.sessionState.StoreAccessStateDAO"</FONT></FONT></FON=
T>
<FONT color=3D#3f5fbf>    <FONT size=3D3><FONT =
face=3DSans>impl-class=3D"au.com.tusc.dao.StoreAccessDAOImpl"</FONT></FON=
T></FONT></PRE>
<P style=3D"MARGIN-BOTTOM: 0in"><IMG height=3D296=20
src=3D"http://www.tusc.com.au/tutorial/images/chap4/StoreAccessStateDAOIm=
pl.png"=20
width=3D812 align=3Dleft border=3D0 name=3DGraphic5><BR =
clear=3Dleft><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>Expand the StoreAccessStateBean node =
under=20
Package Explorer. Right click and a pop up menu will appear. </B></P>
<P><B>On that menu go to Lomboz J2EE &gt; Add EJB to module. Select EJB=20
MyStoreMgr &gt; OK.</B></P>
<P style=3D"MARGIN-BOTTOM: 0in"><FONT color=3D#800000><I>Note : This =
step is covered=20
in previous chapter.</I></FONT></P>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>Expand MyStoreMgr node under MyStore =
Project in=20
Package Explorer. Right click and a pop up menu will appear.</B></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>Go to Lomboz J2EE &gt; Generate EJB =
Classes as=20
shown in figure at right.</B></P>
<P style=3D"MARGIN-BOTTOM: 0in"><IMG height=3D432=20
src=3D"http://www.tusc.com.au/tutorial/images/chap3/GenerateEJBClassesNow=
.png"=20
width=3D474 align=3Dleft border=3D0 name=3DGraphic44><BR =
clear=3Dleft><BR></P>
<TABLE cellSpacing=3D4 cellPadding=3D3 width=3D"100%" border=3D0>

⌨️ 快捷键说明

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