10.12.2012 Views

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

The Java EE 5 Tutorial (PDF) - Oracle Software Downloads

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Creating the converter Web Client<br />

}<br />

}<br />

} catch (Exception ex) {<br />

System.err.println("Caught an unexpected exception!");<br />

ex.printStackTrace();<br />

}<br />

Compiling the converter Application Client<br />

<strong>The</strong> application client files are compiled at the same time as the enterprise bean files, as<br />

described in “Compiling and Packaging the converter Example” on page 645.<br />

Creating the converter Web Client<br />

648<br />

<strong>The</strong> web client is contained in the JSP page<br />

tut-install/javaeetutorial5/examples/ejb/converter/converter-war/web/index.jsp.A<br />

JSP page is a text-based document that contains JSP elements, which construct dynamic<br />

content, and static template data, which can be expressed in any text-based format such as<br />

HTML, WML, and XML.<br />

Coding the converter Web Client<br />

<strong>The</strong> statements (in bold in the following code) for locating the business interface, creating an<br />

enterprise bean instance, and invoking a business method are nearly identical to those of the<br />

application client. <strong>The</strong> parameter of the lookup method is the only difference.<br />

<strong>The</strong> classes needed by the client are declared using a JSP page directive (enclosed within the characters). Because locating the business interface and creating the enterprise bean are<br />

performed only once, this code appears in a JSP declaration (enclosed within the <br />

characters) that contains the initialization method, jspInit, of the JSP page. <strong>The</strong> declaration is<br />

followed by standard HTML markup for creating a form that contains an input field. A scriptlet<br />

(enclosed within the characters) retrieves a parameter from the request and converts it to<br />

a BigDecimal object. Finally, a JSP scriptlet invokes the enterprise bean’s business methods, and<br />

JSP expressions (enclosed within the characters) insert the results into the stream of data<br />

returned to the client.<br />

<br />

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!