我是 J2EE/EJB 领域的新手,我正在学习一些基本示例。我已经实现了一个非常简单的类,它总结了 2 个数字。我有家庭和远程接口以及企业 Bean(无状态)本身。
Adder.java //Remote interface
AdderHome.java //Home interface
AdderBean.java //The EJB class
在将其作为 EJB 应用程序进行测试时,一切正常。但是现在,我想将其作为 JSP 页面进行测试,但在从主界面实例化远程接口时出现错误(实际上没有输出)。
及时:我将 J2EE 1.4 与 JBoss 4 一起使用。
这是 JSP 页面的代码。它应该只打印出一行。
<%@page import="javax.naming.*" %>
<%@page import="javax.rmi.PortableRemoteObject" %>
<%@page import="java.util.Properties" %>
<%@page import="com.lucasmariano.*" %>
<%
//Preparing the properting to be put in the InitialContext
Properties properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
properties.put(Context.PROVIDER_URL, "localhost:1099");
try {
//Get an Initial Context
InitialContext jndiContext = new InitialContext(properties);
System.out.println("got context");
//get a reference to the bean
Object ref = jndiContext.lookup("Adder");
System.out.println("got reference");
//Get a reference to this to the bean's home interface
AdderHome home = (AdderHome) PortableRemoteObject.narrow(ref, AdderHome.class);
out.println("GETTING OBJECT <BR />");
//create an Adder object from the Home interface
//###### HERE IS THE PROBLEM!!! #######
Adder adder = home.create();
out.println("ADDER OBJECT CREATED <BR />");
out.println("2 + 5 = " + adder.add(2,5));
}catch(Exception e ){
System.out.println(e.toString());
}
%>
我需要为我的 web.xml 添加一些新值吗?