Date: Tue, 19 Mar 2024 12:54:33 +0000 (UTC) Message-ID: <1329310270.56857.1710852873127@cwiki-he-fi.apache.org> Subject: Exported From Confluence MIME-Version: 1.0 Content-Type: multipart/related; boundary="----=_Part_56856_1580986164.1710852873127" ------=_Part_56856_1580986164.1710852873127 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Content-Location: file:///C:/exported.html
To run this tutorial, as a minimum you will be required to have installe= d the following prerequisite software:
Details on installing eclipse are provided in the Development environment sec= tion. This tutorial is organized in the following sections:
The application development will take you through the following:
package ejb; import java.math.BigDecimal; import javax.ejb.Remote; @Remote public interface Converter { =09public BigDecimal dollarToRupees(BigDecimal dollars); =09public BigDecimal rupeesToEuro(BigDecimal rupees); }
package ejb; import java.math.BigDecimal; import javax.ejb.*; @Stateless public class ConverterBean implements Converter { =09private BigDecimal rupeeRate =3D new BigDecimal("40.58"); =09private BigDecimal euroRate =3D new BigDecimal("0.018368"); =09public BigDecimal dollarToRupees(BigDecimal dollars) { =09=09BigDecimal result =3D dollars.multiply(rupeeRate); =09=09return result.setScale(2, BigDecimal.ROUND_UP); =09} =09public BigDecimal rupeesToEuro(BigDecimal rupees) { =09=09BigDecimal result =3D rupees.multiply(euroRate); =09=09return result.setScale(2, BigDecimal.ROUND_UP); =09} }
<html> <head> <title>Converter</title> </head> <body bgcolor=3D"white"> <h1>Converter</h1> <hr> <p>Enter an amount to convert:</p> <form method=3D"get" action=3D"index.jsp"> =09<input type=3D"text" name=3D"amount" size=3D"25"><br> =09<p> =09<input type=3D"submit" value=3D"Submit"> =09<input type=3D"reset" value=3D"Reset"> </form> <jsp:include page=3D"/ConverterHandler" /> </body>
package webej= b; import ejb.Converter; import java.io.IOException; import java.io.PrintWriter; import java.math.BigDecimal; import javax.ejb.EJB; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class ConverterHandler extends javax.servlet.http.HttpServlet implem= ents =09=09javax.servlet.Servlet { =09@EJB(name =3D "ejb/Converter") =09private Converter converter; =09protected void doGet(HttpServletRequest request, =09=09=09HttpServletResponse response) throws ServletException, IOException= { =09=09PrintWriter out =3D response.getWriter(); =09=09String amount =3D request.getParameter("amount"); =09=09if (amount !=3D null && amount.length() > 0) { =09=09=09BigDecimal d =3D new BigDecimal(amount); =09=09=09BigDecimal rupeeAmount =3D converter.dollarToRupees(d); =09=09=09out.println("<p>" + amount + " Dollars are " + rupeeAmount += " Rupees.<p>"); =09=09=09BigDecimal euroAmount =3D converter.rupeesToEuro(rupeeAmount); =09=09=09out.println(amount + " Dollars are " + euroAmount + " Euro."); =09=09} =09} =09protected void doPost(HttpServletRequest request, =09=09=09HttpServletResponse response) throws ServletException, IOException= { =09=09doGet(request, response); =09} }
<?xml vers= ion=3D"1.0" encoding=3D"UTF-8"?> <web-app xmlns=3D"http://geronimo.apache.org/xml/ns/j2ee/web-2.0.1"=20 xmlns:nam=3D"http://geronimo.apache.org/xml/ns/naming-1.2"=20 xmlns:sec=3D"http://geronimo.apache.org/xml/ns/security-2.0"=20 xmlns:sys=3D"http://geronimo.apache.org/xml/ns/deployment-1.2"> <sys:environment> <sys:moduleId> <sys:groupId>default</sys:groupId> <sys:artifactId>WebEJB</sys:artifactId> <sys:version>1.0</sys:version> <sys:type>car</sys:type> </sys:moduleId> <sys:dependencies> <sys:dependency> <sys:groupId>default</sys:groupId> <sys:artifactId>CurrencyConvertEJB</sys:artifa= ctId> =09=09 <sys:version>1.0</sys:version> =09=09 <sys:type>car</sys:type> </sys:dependency> =20 </sys:dependencies> </sys:environment> <context-root>/WebEJB</context-root> <nam:ejb-ref xmlns:nam=3D"http://geronimo.apache.org/xml/ns/naming-1= .2"> <nam:ref-name>ejb/Converter</nam:ref-name> <nam:pattern> <nam:groupId>default</nam:groupId> <nam:artifactId>CurrencyConvertEJB</nam:artifactId> <nam:version>1.0</nam:version> <nam:name>ConverterBean</nam:name> </nam:pattern> </nam:ejb-ref> </web-app>