Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/jsp/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
java ejb jsp未报告的异常_Java_Jsp_Ejb_Javabeans - Fatal编程技术网

java ejb jsp未报告的异常

java 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

但是,尝试使用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.jsp

<%@ 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){
    }
}