background image

Creating the converter Web Client

<< Invoking a Business Method | The Converter Class >>
<< Invoking a Business Method | The Converter Class >>

Creating the converter Web Client

System.out.println(
"$" + param + " is " + yenAmount
+
" Yen.");
BigDecimal euroAmount = converter.yenToEuro(yenAmount);
System.out.println(yenAmount +
" Yen is " + euroAmount
+
" Euro.");
System.exit(0);
} catch (Exception ex) {
System.err.println(
"Caught an unexpected exception!");
ex.printStackTrace();
}
}
}
Compiling the converter Application Client
The application client files are compiled at the same time as the enterprise bean files, as
described in
"Compiling and Packaging the converter Example" on page 647
.
Creating the converter Web Client
The web client is contained in the JSP page
tut-install/javaeetutorial5/examples/ejb/converter/converter-war/web/index.jsp. A
JSP page is a text-based document that contains JSP elements, which construct dynamic
content, and static template data, which can be expressed in any text-based format such as
HTML, WML, and XML.
Coding the converter Web Client
The statements (in bold in the following code) for locating the business interface, creating an
enterprise bean instance, and invoking a business method are nearly identical to those of the
application client. The parameter of the lookup method is the only difference.
The 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
performed only once, this code appears in a JSP declaration (enclosed within the <%! %>
characters) that contains the initialization method, jspInit, of the JSP page. The declaration is
followed by standard HTML markup for creating a form that contains an input field. A scriptlet
(enclosed within the <% %> characters) retrieves a parameter from the request and converts it to
a BigDecimal object. Finally, a JSP scriptlet invokes the enterprise bean's business methods, and
JSP expressions (enclosed within the <%= %> characters) insert the results into the stream of data
returned to the client.
Creating the converter Web Client
The Java EE 5 Tutorial · September 2007
650