Converter.java
---------------------------------------------import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.math.*;public interface Converter extends EJBObject {
public BigDecimal dollarToYen(BigDecimal dollars) throws RemoteException;
public BigDecimal yenToEuro(BigDecimal yen) throws RemoteException;
}ConverterHome.java
---------------------------------------------import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;public interface ConverterHome extends EJBHome { Converter create() throws RemoteException, CreateException;
}ConverterBean.java
---------------------------------------------import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.math.*;public class ConverterBean implements SessionBean {
BigDecimal yenRate = new BigDecimal("121.6000");
BigDecimal euroRate = new BigDecimal("0.0077"); public BigDecimal dollarToYen(BigDecimal dollars) { BigDecimal result = dollars.multiply(yenRate);
return result.setScale(2,BigDecimal.ROUND_UP);
} public BigDecimal yenToEuro(BigDecimal yen) { BigDecimal result = yen.multiply(euroRate);
return result.setScale(2,BigDecimal.ROUND_UP);
} public ConverterBean() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}}index.jsp
---------------------------------------------<%@ page import="Converter,ConverterHome,javax.ejb.*, java.math.*, javax.naming.*, javax.rmi.PortableRemoteObject, java.rmi.RemoteException" %>
<%!
private Converter converter = null; public void jspInit() {
try {
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("java:comp/env/ejb/TheConverter");
ConverterHome home = (ConverterHome)PortableRemoteObject.narrow(objRef, ConverterHome.class);
converter = home.create(); } catch (RemoteException ex) {
System.out.println("Couldn't create converter bean."+ ex.getMessage());
} catch (CreateException ex) {
System.out.println("Couldn't create converter bean."+ ex.getMessage());
} catch (NamingException ex) {
System.out.println("Unable to lookup home: "+ "TheConverter "+ ex.getMessage());
}
} public void jspDestroy() {
converter = null;
}
%>
<html>
<head>
<title>Converter</title>
</head><body bgcolor="white">
<h1><b><center>Converter</center></b></h1>
<hr>
<p>Enter an amount to convert:</p>
<form method="get">
<input type="text" name="amount" size="25">
<br>
<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form><%
String amount = request.getParameter("amount");
if ( amount != null && amount.length() > 0 ) {
BigDecimal d = new BigDecimal (amount);
%>
<p>
<%= amount %> dollars are <%= converter.dollarToYen(d) %> Yen.
<p>
<%= amount %> Yen are <%= converter.yenToEuro(d) %> Euro.
<%
}
%></body>
</html>
---------------------------------------------import javax.ejb.EJBObject;
import java.rmi.RemoteException;
import java.math.*;public interface Converter extends EJBObject {
public BigDecimal dollarToYen(BigDecimal dollars) throws RemoteException;
public BigDecimal yenToEuro(BigDecimal yen) throws RemoteException;
}ConverterHome.java
---------------------------------------------import java.io.Serializable;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;public interface ConverterHome extends EJBHome { Converter create() throws RemoteException, CreateException;
}ConverterBean.java
---------------------------------------------import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import java.math.*;public class ConverterBean implements SessionBean {
BigDecimal yenRate = new BigDecimal("121.6000");
BigDecimal euroRate = new BigDecimal("0.0077"); public BigDecimal dollarToYen(BigDecimal dollars) { BigDecimal result = dollars.multiply(yenRate);
return result.setScale(2,BigDecimal.ROUND_UP);
} public BigDecimal yenToEuro(BigDecimal yen) { BigDecimal result = yen.multiply(euroRate);
return result.setScale(2,BigDecimal.ROUND_UP);
} public ConverterBean() {}
public void ejbCreate() {}
public void ejbRemove() {}
public void ejbActivate() {}
public void ejbPassivate() {}
public void setSessionContext(SessionContext sc) {}}index.jsp
---------------------------------------------<%@ page import="Converter,ConverterHome,javax.ejb.*, java.math.*, javax.naming.*, javax.rmi.PortableRemoteObject, java.rmi.RemoteException" %>
<%!
private Converter converter = null; public void jspInit() {
try {
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("java:comp/env/ejb/TheConverter");
ConverterHome home = (ConverterHome)PortableRemoteObject.narrow(objRef, ConverterHome.class);
converter = home.create(); } catch (RemoteException ex) {
System.out.println("Couldn't create converter bean."+ ex.getMessage());
} catch (CreateException ex) {
System.out.println("Couldn't create converter bean."+ ex.getMessage());
} catch (NamingException ex) {
System.out.println("Unable to lookup home: "+ "TheConverter "+ ex.getMessage());
}
} public void jspDestroy() {
converter = null;
}
%>
<html>
<head>
<title>Converter</title>
</head><body bgcolor="white">
<h1><b><center>Converter</center></b></h1>
<hr>
<p>Enter an amount to convert:</p>
<form method="get">
<input type="text" name="amount" size="25">
<br>
<p>
<input type="submit" value="Submit">
<input type="reset" value="Reset">
</form><%
String amount = request.getParameter("amount");
if ( amount != null && amount.length() > 0 ) {
BigDecimal d = new BigDecimal (amount);
%>
<p>
<%= amount %> dollars are <%= converter.dollarToYen(d) %> Yen.
<p>
<%= amount %> Yen are <%= converter.yenToEuro(d) %> Euro.
<%
}
%></body>
</html>
解决方案 »
- 新手求教:ORA-01722: 无效数字问题,知道原因,但没找到问题所在
- 电子商务、网上支付平台
- Junit是hibernate里的东西吗?
- (转贴)程序员职业的发展前景及成为程序员所要具备的几个条件
- 连接数据库sql 2000
- 问一个hibernate查询方面的问题,请了解相关内容的高手解答
- 高分求助一个关于“URL重写”的问题!!!谢谢指点!
- 到底怎样才能学好java?
- 安装jakarta-tomcat-5.0.27.exe时,进行大约不到一分钟就停止,提示:“using Jvm:D:\jdk\jre\bin\server\jvm.dll”
- 关于big5和URLDecoder的问题
- i'm louis i'm in chongqing china,i'm love java,i want have to many friend of java.if u want,call me.
- EIS系统是什么?
都告诉你怎么部署EJB
怎么调用现在写的源程序对你没什么用
你自己还要部署之类的
看一看帮助吧不要看JSF之类控件的东西
你只要看看EJB的就行
代码是小事。
我曾经为了不小心ejb-jar.xml,weblogic-ejb-jar.xml的一点烦了很久。
这个 java:comp/env/ejb/TheConverter 是什么啊 关键字?