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

📄 ejb4.html

📁 j2eePDF格式的电子书
💻 HTML
📖 第 1 页 / 共 2 页
字号:
public class ConverterClient {&nbsp;&nbsp;public static void main(String[] args) {&nbsp;&nbsp;&nbsp;&nbsp;try {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Context initial = new InitialContext();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Object objref = initial.lookup&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(&quot;java:comp/env/ejb/SimpleConverter&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ConverterHome home = &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(ConverterHome)PortableRemoteObject.narrow(objref, &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ConverterHome.class);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Converter currencyConverter = home.create();&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BigDecimal param = new BigDecimal (&quot;100.00&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;BigDecimal amount =&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;currencyConverter.dollarToYen(param);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(amount);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;amount = currencyConverter.yenToEuro(param);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.out.println(amount);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.exit(0);&nbsp;&nbsp;&nbsp;&nbsp;} catch (Exception ex) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;System.err.println(&quot;Caught an unexpected exception!&quot;);&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;ex.printStackTrace();&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;} }<a name="wp79939"> </a></pre></div><a name="wp79940"> </a><h3 class="pHeading2">Compiling the Application Client</h3><a name="wp79941"> </a><p class="pBody">The application client files are compiled at the same time as the enterprise bean files, as described in <a  href="EJB3.html#wp79846">Compiling the Source Files</a>.</p><a name="wp79947"> </a><h3 class="pHeading2">Packaging the J2EE Application Client</h3><a name="wp79948"> </a><p class="pBody">To package an application client component, you run the New Application Client wizard of the <code class="cCode">deploytool</code>. During this process the wizard performs the following tasks.</p><div class="pSmartList1"><ul class="pSmartList1"><a name="wp79949"> </a><div class="pSmartList1"><li>Creates the application client's deployment descriptor</li></div><a name="wp79950"> </a><div class="pSmartList1"><li>Puts the deployment descriptor and client files into a JAR file</li></div><a name="wp81117"> </a><div class="pSmartList1"><li>Adds the JAR file to the application's <code class="cCode">ConverterApp.ear</code> file</li></div></ul></div><a name="wp79954"> </a><p class="pBody">To start the New Application Client wizard, select File<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>New<span style="font-family: Symbol"><img src="images/arrwrite.gif" border="0" alt="Right Arrow"></span>Application Client. The wizard displays the following dialog boxes.</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp79955"> </a><div class="pSmartList1"><li>Introduction dialog box </li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp79956"> </a><div class="pSmartList2"><li>Read the explanatory text for an overview of the wizard's features. </li></div><a name="wp79957"> </a><div class="pSmartList2"><li>Click Next.</li></div></ol></div><a name="wp79958"> </a><div class="pSmartList1"><li> JAR File Contents dialog box</li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp80802"> </a><div class="pSmartList2"><li>Select the button labelled Create New AppClient Module in Application.</li></div><a name="wp81129"> </a><div class="pSmartList2"><li>In the combo box below this button, select <code class="cCode">ConverterApp</code>.</li></div><a name="wp81130"> </a><div class="pSmartList2"><li>In the AppClient Display Name field, enter <code class="cCode">ConverterClient</code>.</li></div><a name="wp79960"> </a><div class="pSmartList2"><li>Click Edit.</li></div><a name="wp79961"> </a><div class="pSmartList2"><li>In the tree under Available Files, locate this directory:</li></div><a name="wp81539"> </a><p class="pBodyRelative"><code class="cCode">&lt;</code><code class="cVariable">INSTALL</code><code class="cCode">&gt;/j2eetutorial14/examples/ejb/converter/build/</code> </p><a name="wp79962"> </a><div class="pSmartList2"><li>Select the <code class="cCode">ConverterClient.class</code> file</li></div><a name="wp80822"> </a><div class="pSmartList2"><li>Click Add. </li></div><a name="wp79963"> </a><div class="pSmartList2"><li>Click OK.</li></div><a name="wp79964"> </a><div class="pSmartList2"><li>Click Next.</li></div></ol></div><a name="wp79965"> </a><div class="pSmartList1"><li>General dialog box </li></div><div class="pSmartList2"><ol type="a" class="pSmartList2"><a name="wp79966"> </a><div class="pSmartList2"><li>In the Main Class combo box, select <code class="cCode">ConverterClient</code>.</li></div><a name="wp79969"> </a><div class="pSmartList2"><li>Click Next.</li></div><a name="wp79970"> </a><div class="pSmartList2"><li>Click Finish.</li></div></ol></div></ol></div><a name="wp79972"> </a><h3 class="pHeading2">Specifying the Application Client's Enterprise Bean Reference</h3><a name="wp79974"> </a><p class="pBody">When it invokes the <code class="cCode">lookup</code> method, the <code class="cCode">ConverterClient</code> refers to the home of an enterprise bean:</p><div class="pPreformattedRelative"><pre class="pPreformattedRelative">Object objref = myEnv.lookup(&quot;ejb/SimpleConverter&quot;);<a name="wp79975"> </a></pre></div><a name="wp79976"> </a><p class="pBody">You specify this reference as follows.</p><div class="pSmartList1"><ol type="1" class="pSmartList1"><a name="wp79977"> </a><div class="pSmartList1"><li>In the tree, select <code class="cCode">ConverterClient</code>.</li></div><a name="wp79978"> </a><div class="pSmartList1"><li>Select the EJB Refs tab.</li></div><a name="wp79979"> </a><div class="pSmartList1"><li>Click Add.</li></div><a name="wp79980"> </a><div class="pSmartList1"><li>In the Coded Name field, enter <code class="cCode">ejb/SimpleConverter</code>.</li></div><a name="wp79981"> </a><div class="pSmartList1"><li>In the EJB Type field, select Session.</li></div><a name="wp79982"> </a><div class="pSmartList1"><li>In the Interfaces field, select Remote.</li></div><a name="wp79983"> </a><div class="pSmartList1"><li>In the Home Interface column, field converter.<code class="cCode">ConverterHome</code>.</li></div><a name="wp79984"> </a><div class="pSmartList1"><li>In the Local/Remote Interface field, enter <code class="cCode">converter.Converter</code>.</li></div><a name="wp80851"> </a><div class="pSmartList1"><li>In the Enterprise Bean Name field, enter <code class="cCode">ConverterEJB</code>.</li></div><a name="wp80849"> </a><div class="pSmartList1"><li>Click OK.</li></div></ol></div>    </blockquote>   <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider">    <table width="550" summary="layout" id="SummaryNotReq1">      <tr>	<td align="left" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/download.html#tutorial" target="_blank">Download</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/faq.html" target="_blank">FAQ</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/history.html" target="_blank">History</a>	</td>        <td align="center" valign="center"><a accesskey="p" href="EJB3.html"><img id="LongDescNotReq1" src="images/PrevArrow.gif" width="26" height="26" border="0" alt="Prev" /></a><a accesskey="c" href="J2EETutorialFront.html"><img id="LongDescNotReq1" src="images/UpArrow.gif" width="26" height="26" border="0" alt="Home" /></a><a accesskey="n" href="EJB5.html"><img id="LongDescNotReq3" src="images/NextArrow.gif" width="26" height="26" border="0" alt="Next" /></a><a accesskey="i" href="J2EETutorialIX.html"></a>        </td>	<td align="right" valign="center">	<font size="-1">	<a href="http://java.sun.com/j2ee/1.4/docs/api/index.html" target="_blank">API</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/search.html" target="_blank">Search</a>	<br>	<a href="http://java.sun.com/j2ee/1.4/docs/tutorial/information/sendusmail.html" target="_blank">Feedback</a></font>	</font>	</td>      </tr>    </table>    <img src="images/blueline.gif" width="550" height="8" ALIGN="BOTTOM" NATURALSIZEFLAG="3" ALT="Divider"><p><font size="-1">All of the material in <em>The J2EE(TM) 1.4 Tutorial</em> is <a href="J2EETutorialFront2.html">copyright</a>-protected and may not be published in other workswithout express written permission from Sun Microsystems.</font>  </body></html>

⌨️ 快捷键说明

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