<%@
page
import
=
"com.sap.tutorial.javaee.ConverterLocal,
java.math.*, javax.naming.*"
%>
<%!
private
ConverterLocal converterBean =
null
;
public
void
jspInit() {
try
{
InitialContext ic =
new
InitialContext();
converterBean = (ConverterLocal)
ic.lookup(
"java:comp/env/Converter"
);
}
catch
(Exception ex) {
System.out.println(
"Couldn't create converter bean."
+
ex.getMessage());
}
}
public
void
jspDestroy() {
converterBean =
null
;
}
%>
<
html
>
<
head
>
<
title
>
Currency Converter
</
title
>
</
head
>
<
body
>
<
h1
>
Currency Converter
</
h1
>
<
hr
>
<
p
>
Enter an amount to convert:
</
p
>
<
form
method
=
"get"
>
<
input
type
=
"text"
name
=
"amount"
size
=
"20"
>
<
input
type
=
"submit"
value
=
"Submit"
>
</
form
>
<%
String amount = request.getParameter(
"amount"
);
if
( amount !=
null
&& amount.length() > 0 ) {
BigDecimal value =
new
BigDecimal(amount);
BigDecimal euroAmount = converterBean.dollarToEuro(value);
%>
<
p
>
<%=
amount
%>
USD are
<%=
euroAmount
%>
EUR
<
br
>
<%
BigDecimal dollarAmount =
converterBean.euroToDollar(value);
%>
<%=
amount
%>
EUR are
<%=
dollarAmount
%>
USD
</
p
>
<%
}
%>
</
body
>
</
html
>
|
<
ejb-local-ref
>
<
ejb-ref-name
>
Converter
</
ejb-ref-name
>
<
ejb-ref-type
>
Session
</
ejb-ref-type
>
<
local
>
com.sap.tutorial.javaee.ConverterLocal
</
local
>
</
ejb-local-ref
>
|