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

📄 3.mht

📁 Enterprise Java Bean的PPT文档,很好的东西.
💻 MHT
📖 第 1 页 / 共 5 页
字号:
color=3D#7f0055>protected</FONT></B> <FONT =
color=3D#000000>SessionContext</FONT>=20
<FONT color=3D#000000>ctx;</FONT></FONT></FONT></P>
<P><B>Add method setSessionContext with sessionContext as parameter and =
assign=20
that to the sessionContext variable as shown below in the code =
snippet.</B></P>
<P><IMG height=3D290=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/StoreAccessBean.png=
"=20
width=3D392 align=3Dleft border=3D0 name=3DGraphic11><BR =
clear=3Dleft><B>Similarly add=20
method unsetSessionContext, assign context variable to null as shown=20
above.</B></P>
<P><FONT color=3D#800000><I>Note : StoreAccessSession class inherits the =

StoreAccessBean abstract class and implements <FONT=20
face=3D"Nimbus Roman No9 L">SessionBean, which will override all methods =
of=20
interface SessionBean. So after finishing the methods in the bean class, =

generate your EJB classes again. SessionContext methods will be =
overridden as=20
shown in figure below. </FONT>Code snippet from StoreAccessSession shown =

below.</I></FONT></P>
<P><IMG height=3D151=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/StoreAccessSessionC=
ontextMethods.png"=20
width=3D375 align=3Dleft border=3D0 name=3DGraphic25><BR =
clear=3Dleft><BR><BR></P>
<P><B>Now let's look at the generated Home and Remote =
interfaces.</B></P>
<P><B>In the case of the Remote interface all business methods declared =
in the=20
bean are also generated with the same signature. This is due to the =
class level=20
tag declared in the StoreAccess Bean as discussed above after adding =
business=20
methods. Code snippet for tag is shown below. </B></P>
<P><IMG height=3D103=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/SessionBeanInterfac=
eTag.png"=20
width=3D359 align=3Dleft border=3D0 name=3DGraphic42><BR =
clear=3Dleft><BR><BR></P>
<P><B>So, loginUser is generated in a Remote Interface called =
StoreAccess as=20
shown below because of this tag. </B></P>
<P><IMG height=3D223=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/SessionBeanRemoteIn=
terface.png"=20
width=3D523 align=3Dleft border=3D0 name=3DGraphic23><BR =
clear=3Dleft><BR><BR></P>
<P><B>In the case of the Home Interface only one method is created named =

'create', which is generated by default because of the =
&lt;homeinterface/&gt;=20
tag in ejbGenerate.xml as shown below.</B></P>
<P><IMG height=3D313=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/SessionBeanHome.png=
"=20
width=3D467 align=3Dleft border=3D0 name=3DGraphic24><BR =
clear=3Dleft><BR><BR></P>
<P><B>Also, other then that, it has JNDI_NAME and COMP_NAME (which is =
the=20
logical name to lookup the component) is also generated, these are =
generated=20
because of this tag declared at class level in 'StoreAccessBean' class =
shown=20
below in figure. </B></P>
<P><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=3DGraphic41><BR =
clear=3Dleft><FONT=20
color=3D#800000><I>Note : For further options associated with these tags =
please=20
refer to the 'ejbdoclet' documentation in Xdoclet.</I></FONT></P>
<P style=3D"MARGIN-BOTTOM: 0in"><B>Now, all the aspects are pretty much =
covered,=20
and our bean's functionality is complete. Now for the deployment=20
descriptors..</B></P>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><B>Deploy Bean =
:</B></H3>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P>In order to deploy our bean we have to declare a few tags in the=20
StoreAccessBean class as shown below in the code snippet.</P>
<P><IMG height=3D273=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/StoreAccessBeanAllD=
escriptors.png"=20
width=3D406 align=3Dleft border=3D0 name=3DGraphic28><BR =
clear=3Dleft><BR><BR></P>
<P><B>Add the tag shown below in at the class level (at the =
top).</B></P><PRE><FONT face=3DSans><FONT size=3D3><FONT =
color=3D#3f5fbf>@ejb.resource</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>ref</FONT> <FONT color=3D#3f5fbf>res</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT color=3D#3f5fbf>ref</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>name=3D"jdbc/DefaultDS"</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT color=3D#3f5fbf>res</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>type=3D"javax.sql.Datasource"</FONT></FONT></FONT>
<FONT face=3DSans><FONT size=3D3><FONT color=3D#3f5fbf>res</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>auth=3D"Container"</FONT></FONT></FONT></PRE>
<P><B>This tag will generate deployment descriptors in ejb-jar.xml, as =
the bean=20
has to know which datasource you are going to connect to, what is its =
type, etc.=20
This will generate these descriptors as shown in code snippet =
below.</B></P>
<P><IMG height=3D299=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/ejb-jarResourceRef.=
png"=20
width=3D473 align=3Dleft border=3D0 name=3DGraphic16><BR =
clear=3Dleft><BR><BR></P>
<P><B>Add the tag shown below in StoreAccessBean at the class level (at =
the=20
top).</B></P><PRE style=3D"MARGIN-BOTTOM: 0.2in"><FONT face=3DSans><FONT =
size=3D3><FONT color=3D#3f5fbf>@jboss.resource</FONT><FONT =
color=3D#7f7f9f>-</FONT><FONT color=3D#3f5fbf>ref</FONT> <FONT =
color=3D#3f5fbf>res</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>ref</FONT><FONT color=3D#7f7f9f>-</FONT><FONT =
color=3D#3f5fbf>name=3D"jdbc/DefaultDS" jndi<FONT =
color=3D#7f7f9f>-</FONT>name=3D"java:/DefaultDS<B>"</B></FONT></FONT></FO=
NT></PRE>
<P><B>This tag will generate deployment descriptors in jboss.xml, as the =

application server has to know with what jndi-name datasource it has =
been=20
registered with. This will generate these descriptors as shown in the =
code=20
snippet below.</B></P>
<P><IMG height=3D147=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/jbossResourceRef..p=
ng"=20
width=3D329 align=3Dleft border=3D0 name=3DGraphic27><BR =
clear=3Dleft><BR><BR></P>
<P>Now, everything is complete, and it's time to deploy the bean.</P>
<P><B>First, regenerate your EJB classes as shown in the steps above for =
the=20
final time.</B></P>
<P><FONT color=3D#800000><I>Note : We have regenerated the classes again =
and=20
again, in order to explain every step and its result. Once you are =
familiar with=20
these steps you will need much fewer of these iterations. Either way, it =
doesn't=20
matter, as your implementation always remains untouched by this=20
process.</I></FONT></P>
<P><B>Go to Lomboz J2EE View &gt; expand node MyStore &gt; expand =
MyStoreMgr=20
&gt; select 'Jboss 3.2.1 ALL' .</B></P>
<P><B>Right click &gt; select Debug Sever on the pop up menu as shown in =
figure=20
below.</B></P>
<P><IMG height=3D180=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/LombozJ2EEDebugServ=
er.png"=20
width=3D300 align=3Dleft border=3D0 name=3DGraphic29><BR =
clear=3Dleft><BR><BR></P>
<P><B>Go to MyStoreMgr node in LombozJ2EE view &gt; right click &gt; =
select=20
Deploy on the pop up menu as shown in the figure below</B>.</P>
<P><IMG height=3D169=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/LombozJ2EEDeploy.pn=
g"=20
width=3D298 align=3Dleft border=3D0 name=3DGraphic30><BR =
clear=3Dleft><BR><BR></P>
<P>And now wait for your deployment result.</P>
<P>If everything goes fine, you will have this message under your =
console as=20
shown in the figure below.</P>
<P><IMG height=3D434=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/LombozJ2EEBeanDeplo=
yed.png"=20
width=3D828 align=3Dleft border=3D0 name=3DGraphic31><BR =
clear=3Dleft><BR><BR></P>
<P>So, now our bean is deployed successfully, let's create our test =
client,=20
which will invoke the loginUser method on 'StoreAccessBean'.</P>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><BR></H3>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><B>Create your Test =
Client=20
:</B></H3>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P>G<B>o to Project MytStore node &gt; select src node &gt; right =
click.</B></P>
<P><B>Select New on pop up menu &gt; select Lomboz EJB Test Client =
Wizard</B> as=20
shown in the figure below. </P>
<P><IMG height=3D232=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/CreateEJBTestClient=
.png"=20
width=3D507 align=3Dleft border=3D0 name=3DGraphic32><BR =
clear=3Dleft><BR><BR></P>
<P><B>Select package name au.com.tusc.client, name as SessionClient and =
select=20
Ejb Home as au.com.tusc.session.StoreAccessHome and Ejb Interface as=20
au.com.tusc.session.StoreAccess</B> <B>as shown in the figure =
below</B>.</P>
<P><IMG height=3D454=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/CreateEJBTestClient=
PackageName.png"=20
width=3D523 align=3Dleft border=3D0 name=3DGraphic33><BR =
clear=3Dleft><BR><BR></P>
<P>This will generate the required methods for you in your SessionClient =
class=20
and you have to just invoke the loginUser method on the bean as shown =
below.</P>
<P><IMG height=3D533=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/SessionCleint.png" =
width=3D724=20
align=3Dleft border=3D0 name=3DGraphic34><BR clear=3Dleft><BR><BR></P>
<P>Now the last step is to write code in your client.</P>
<P><B>So add these lines under the testBean </B>method as shown in =
figure=20
below<B>. </B></P><PRE><FONT face=3DSans><FONT style=3D"FONT-SIZE: 11pt" =
size=3D2><FONT color=3D#000000>System.out.println(</FONT><FONT =
color=3D#2a00ff>"Request from client : "</FONT><FONT =
color=3D#000000>);</FONT></FONT></FONT>
<FONT face=3DSans><FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
color=3D#000000>System.out.println(</FONT><FONT color=3D#2a00ff>"Reply =
from Server: Your userid is "</FONT> <FONT =
color=3D#000000>+</FONT></FONT></FONT>
<FONT face=3DSans><FONT style=3D"FONT-SIZE: 11pt" size=3D2><FONT =
color=3D#000000>myBean.loginUser(</FONT><FONT =
color=3D#2a00ff>"ANDY"</FONT><FONT color=3D#000000>,</FONT><FONT =
color=3D#2a00ff>"PASSWD"</FONT><FONT =
color=3D#000000>));</FONT></FONT></FONT></PRE>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P style=3D"MARGIN-BOTTOM: 0in"><IMG height=3D409=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/SessionCleintAddLog=
inUser.png"=20
width=3D610 align=3Dleft border=3D0 name=3DGraphic35><BR =
clear=3Dleft><BR></P>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><BR></H3>
<H3 style=3D"MARGIN-TOP: 0in; MARGIN-BOTTOM: 0in"><B>Test your Client =
:</B></H3>
<P style=3D"MARGIN-BOTTOM: 0in"><BR></P>
<P><B>Now, in order to test your client, Select SessionClient node &gt; =
Go at=20
top level menu and select the icon with the 'Running Man'</B>.</P>
<P><B>On that select 'Run as' &gt; select 'Java Application'</B>, as =
shown=20
below.</P>
<P><IMG height=3D328=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/RunSessionClient.pn=
g"=20
width=3D578 align=3Dleft border=3D0 name=3DGraphic36><BR =
clear=3Dleft><BR><BR></P>
<P><B>Now under your console, if you get your reply for 'ANDY' as 'U2', =
then=20
your call is successful as shown below.</B></P>
<P><IMG height=3D401=20
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/TestClient'sResult.=
png"=20
width=3D646 align=3Dleft border=3D0 name=3DGraphic37><BR =
clear=3Dleft><BR><BR></P>
<P><FONT color=3D#800000><I>Note : So our Stateless Session Bean is =
deployed and=20
tested successfully and from now onwards you should be comfortable using =
Lomboz.=20
In future we will not go into the detail of the steps for using Lomboz =
and will=20
concentrate more on other aspects of beans.</I></FONT></P>
<TABLE cellSpacing=3D0 cellPadding=3D0 width=3D"100%" border=3D0>
  <THEAD>
  <TR vAlign=3Dtop>
    <TD width=3D"33%"><A =
href=3D"http://www.tusc.com.au/tutorial/html/chap2.html"=20
      name=3DChapter2><IMG height=3D35=20
      =
src=3D"file:///F:/java_trainning/1206/tuscejb/3.files/PrevArrow.png"=20
      width=3D51 align=3Dleft border=3D0 name=3DGraphic15><BR =
clear=3Dleft></A></TD>
    <TD width=3D"33%">

⌨️ 快捷键说明

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