当前位置: 技术问答>java相关
初学ejb的问题,解决问题保证得分
来源: 互联网 发布时间:2017-03-15
本文导语: 小弟初学ejb,遇到配置上的问题 先说一下开发工具 ejb我用jbuilder 7编写 jbuilder 7里的ejb server选用jboss 3.0(单纯的jboss,没有加tomcat) jsp web server我选用resin 2.1,端口8028(resin速度快,好调试) 入门当然是首先编...
小弟初学ejb,遇到配置上的问题
先说一下开发工具
ejb我用jbuilder 7编写
jbuilder 7里的ejb server选用jboss 3.0(单纯的jboss,没有加tomcat)
jsp web server我选用resin 2.1,端口8028(resin速度快,好调试)
入门当然是首先编一个hello world,代码如下
Hello.java代码
package net.eschool.test;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
public interface Hello extends javax.ejb.EJBObject {
public String getText() throws RemoteException;
}
///////////////////////////////
HelloBean.java代码
package net.eschool.test;
import javax.ejb.*;
public class HelloBean implements SessionBean {
SessionContext sessionContext;
public void ejbCreate(){
System.out.println("call ejbCreate()");
}
public void ejbRemove() {
System.out.println("call ejbRemove()");
}
public void ejbActivate() {
System.out.println("call ejbActivate()");
}
public void ejbPassivate() {
System.out.println("call ejbPassivate()");
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
public String getText() {
System.out.println("hello");
return "Hello World!";
}
}
///////////////////////////////
HelloHome.java代码
package net.eschool.test;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
public interface HelloHome extends javax.ejb.EJBHome {
public Hello create() throws CreateException, RemoteException;
}
/////////////////////////////
ejb-jar.xml内容
Hello
Hello
net.eschool.test.HelloHome
net.eschool.test.Hello
net.eschool.test.HelloBean
Stateless
Container
Hello
*
Required
////////////////////////////
jboss.xml内容
Hello
Hello
////////////////////////////
客户端test.jsp代码
我将打包好的jar文件复制到D:jboss-3.0.4serverdefaultdeploy下,运行jboss无误,在resin里发布test.jsp时出现如下错误
Note: sun.tools.javac.Main has been deprecated.
/school/test.jsp:15: Package net.eschool.test not found in import.
import net.eschool.test.*;
^
1 error, 1 warning
ejb应该怎么设置?
先说一下开发工具
ejb我用jbuilder 7编写
jbuilder 7里的ejb server选用jboss 3.0(单纯的jboss,没有加tomcat)
jsp web server我选用resin 2.1,端口8028(resin速度快,好调试)
入门当然是首先编一个hello world,代码如下
Hello.java代码
package net.eschool.test;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
public interface Hello extends javax.ejb.EJBObject {
public String getText() throws RemoteException;
}
///////////////////////////////
HelloBean.java代码
package net.eschool.test;
import javax.ejb.*;
public class HelloBean implements SessionBean {
SessionContext sessionContext;
public void ejbCreate(){
System.out.println("call ejbCreate()");
}
public void ejbRemove() {
System.out.println("call ejbRemove()");
}
public void ejbActivate() {
System.out.println("call ejbActivate()");
}
public void ejbPassivate() {
System.out.println("call ejbPassivate()");
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
public String getText() {
System.out.println("hello");
return "Hello World!";
}
}
///////////////////////////////
HelloHome.java代码
package net.eschool.test;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
public interface HelloHome extends javax.ejb.EJBHome {
public Hello create() throws CreateException, RemoteException;
}
/////////////////////////////
ejb-jar.xml内容
Hello
Hello
net.eschool.test.HelloHome
net.eschool.test.Hello
net.eschool.test.HelloBean
Stateless
Container
Hello
*
Required
////////////////////////////
jboss.xml内容
Hello
Hello
////////////////////////////
客户端test.jsp代码
我将打包好的jar文件复制到D:jboss-3.0.4serverdefaultdeploy下,运行jboss无误,在resin里发布test.jsp时出现如下错误
Note: sun.tools.javac.Main has been deprecated.
/school/test.jsp:15: Package net.eschool.test not found in import.
import net.eschool.test.*;
^
1 error, 1 warning
ejb应该怎么设置?
|
test.jsp没有找到net.eschool.test包,你要把net.eschool.test包加到CLASSPATH里去,或者放在test.jsp所在的web-infclasses
|
上面这位仁兄回答了问题,为何没有得分呢
|
楼上说得对
|
我把net.eschool.test包加到CLASSPATH里也不行,出现错误是
java.lang.NullPointerException
at _school._test__jsp._jspService(/school/test.jsp:10)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:312)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:536)
请问什么原因?
java.lang.NullPointerException
at _school._test__jsp._jspService(/school/test.jsp:10)
at com.caucho.jsp.JavaPage.service(JavaPage.java:75)
at com.caucho.jsp.Page.subservice(Page.java:485)
at com.caucho.server.http.FilterChainPage.doFilter(FilterChainPage.java:182)
at com.caucho.server.http.Invocation.service(Invocation.java:312)
at com.caucho.server.http.CacheInvocation.service(CacheInvocation.java:135)
at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:221)
at com.caucho.server.http.HttpRequest.handleConnection(HttpRequest.java:163)
at com.caucho.server.TcpConnection.run(TcpConnection.java:137)
at java.lang.Thread.run(Thread.java:536)
请问什么原因?
|
nullpoint 说明有地方 为null 了
可能是Context ejb,
或者是HelloHome home
Context ejb = (Context) new InitialContext().lookup("java:comp/env/ejb");
首先这里System.out 1下 看一下 是否lookup正确,我看你的jndi是Hello,为什么lookup ejb ,你调试一下
HelloHome home = (HelloHome) ejb.lookup("Hello");
应该用一下方法,比较标准
HelloHome home = (HelloHome ) javax.rmi.PortableRemoteObject.narrow(ref, HelloHome .class);
good luck
可能是Context ejb,
或者是HelloHome home
Context ejb = (Context) new InitialContext().lookup("java:comp/env/ejb");
首先这里System.out 1下 看一下 是否lookup正确,我看你的jndi是Hello,为什么lookup ejb ,你调试一下
HelloHome home = (HelloHome) ejb.lookup("Hello");
应该用一下方法,比较标准
HelloHome home = (HelloHome ) javax.rmi.PortableRemoteObject.narrow(ref, HelloHome .class);
good luck