java ejb jsp未报告的异常
但是,尝试使用jsp与bean交互时,在运行它时会出现一些错误 以下是我在浏览器中看到的错误 生成的servlet错误: [javac]C:\Sun\AppServerNew\domains\domain1\generated\jsp\j2ee apps\ConverterApp\war-ic\u war\org\apache\jsp\index\u jsp.java:21:未报告的异常javax.naming.NamingException;必须被抓住或宣布被抛出 [javac]InitialContext ic=new InitialContext(); ^ 生成的servlet错误: [javac]C:\Sun\AppServerNew\domains\domain1\generated\jsp\j2ee apps\ConverterApp\war-ic\u war\org\apache\jsp\index\u jsp.java:22:未报告的异常javax.naming.NamingException;必须被抓住或宣布被抛出 [javac]objectobjref=ic.lookup(“java:comp/env/ejb/Converter”); ^ 生成的servlet错误: [javac]C:\Sun\AppServerNew\domains\domain1\generated\jsp\j2ee apps\ConverterApp\war-ic\u war\org\apache\jsp\index\u jsp.java:24:未报告的异常javax.ejb.CreateException;必须被抓住或宣布被抛出 [javac]converter=home.create() index.jspjava ejb jsp未报告的异常,java,jsp,ejb,javabeans,Java,Jsp,Ejb,Javabeans,但是,尝试使用jsp与bean交互时,在运行它时会出现一些错误 以下是我在浏览器中看到的错误 生成的servlet错误: [javac]C:\Sun\AppServerNew\domains\domain1\generated\jsp\j2ee apps\ConverterApp\war-ic\u war\org\apache\jsp\index\u jsp.java:21:未报告的异常javax.naming.NamingException;必须被抓住或宣布被抛出 [javac]Initial
<%@ page import="converter.Converter, converter.ConverterHome, java.math.*, javax.ejb.*, 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/Converter");
ConverterHome home = (ConverterHome)PortableRemoteObject.narrow(objRef, ConverterHome.class);
converter = home.create();
} catch (RemoteException ex) {
}
}
%>
<html>
<head>
<title>Converter</title>
</head>
<body bgcolor="white">
<h1><center>Converter</center></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>
转炉
package converter;
import java.rmi.RemoteException;
import javax.ejb.*;
public interface ConverterHome extends EJBHome {
Converter create() throws CreateException, RemoteException;
}
转换器
package converter;
import java.rmi.RemoteException;
import javax.ejb.*;
import java.math.*;
public interface Converter extends EJBObject{
public BigDecimal dollarToYen(BigDecimal dollars)
throws RemoteException;
public BigDecimal yenToEuro(BigDecimal dollars)
throws RemoteException;
}
在
RemoteException
之后,您需要在ur.jsp
文件上调用NamingException
和CreateException
,将index.jsp
中的jspInit()
方法更改为:
public void jspInit() {
try {
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("java:comp/env/ejb/Converter");
ConverterHome home = (ConverterHome) PortableRemoteObject.narrow(objRef, ConverterHome.class);
converter = home.create();
}catch(NamingException ne){
}catch (RemoteException ex) {
}catch(CreateException ce){
}
}
public void jspInit() {
try {
InitialContext ic = new InitialContext();
Object objRef = ic.lookup("java:comp/env/ejb/Converter");
ConverterHome home = (ConverterHome) PortableRemoteObject.narrow(objRef, ConverterHome.class);
converter = home.create();
}catch(NamingException ne){
}catch (RemoteException ex) {
}catch(CreateException ce){
}
}