저는 J2EE/EJB 필드의 초보자입니다. 몇 가지 기본 예제를 따르고 있습니다. 나는 2 개의 숫자를 합친 매우 간단한 클래스를 구현했다. 나는 집과 원격 인터페이스와 엔터 프라이즈 빈 (stateless) 자체를 가지고있다.EJB + JSP : 홈 인터페이스에서 원격 객체를 만들 수 없습니다.
Adder.java //Remote interface
AdderHome.java //Home interface
AdderBean.java //The EJB class
EJB 응용 프로그램으로 테스트 할 때 모든 것이 완벽하게 작동합니다. 하지만 이제는 JSP 페이지로 테스트하고 싶지만 원격 인터페이스가 홈 인터페이스에서 인스턴스화되는 시점에 오류가 발생합니다. 실제로 출력이 없습니다. 시간에
: 나는 보스 4.
으로 J2EE 1.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 년에 출판 된 책을 팔로우하고 있습니다. 나는 이런 식으로 모든 것이 완전히 바뀌 었다고 상상하지 못했다. (프로그래밍 언어에 관한 것이지만 시간이 지남에 따라 많이 달라진다. uptodate하기 위해 EJB3와 EJB3.1에 관한 자료를 찾을 것입니다. 고마워. – LucasM