我是J2EE/EJB領域的新手,我正在關注一些基本示例。我已經實現了一個總結2個數字的非常簡單的類。我有家庭和遠程接口以及Enterprise Bean(無狀態)本身。EJB + JSP:無法從主頁界面創建遠程對象
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添加一些新值?
事實上,我正在關注2002年出版的一本書。但是,我沒有想到事情會以這種方式完全改變(即使它是關於編程語言的,而且我知道它隨時間變化很大)。我會尋找一些關於EJB3和EJB3.1的資料,使其成爲最新的。非常感謝。 – LucasM 2011-03-05 18:00:38