这是我的代码:
界面:
package pack;
import javax.ejb.Remote;
@Remote
public interface DemoRemote extends javax.ejb.EJBObject {
String disp (String name) throws java.rmi.RemoteException;
}
类别:
package pack;
import javax.ejb.EJBHome;
import javax.ejb.EJBObject;
import javax.ejb.Handle;
import javax.ejb.RemoveException;
import javax.ejb.SessionBean;
import javax.ejb.Stateless;
import weblogic.ejb.GenericSessionBean;
import weblogic.ejbgen.Session;
import weblogic.ejbgen.JndiName;
import weblogic.ejbgen.FileGeneration;
import weblogic.ejbgen.Constants;
@Session(ejbName = "Demo")
@JndiName(remote = "ejb.DemoRemoteHome")
@FileGeneration(remoteClass = Constants.Bool.TRUE, remoteHome = Constants.Bool.TRUE, localClass = Constants.Bool.FALSE, localHome = Constants.Bool.FALSE)
@Stateless
public class Demo extends GenericSessionBean implements SessionBean, DemoRemote {
private static final long serialVersionUID = 1L;
/* (non-Javadoc)
* @see weblogic.ejb.GenericSessionBean#ejbCreate()
*/
public void ejbCreate() {
// IMPORTANT: Add your code here
}
public String disp(String name) {
return "Hello " + name;
}
public EJBHome getEJBHome() {
// TODO Auto-generated method stub
return null;
}
public Handle getHandle() {
// TODO Auto-generated method stub
return null;
}
public Object getPrimaryKey() {
// TODO Auto-generated method stub
return null;
}
public boolean isIdentical(EJBObject obj) {
// TODO Auto-generated method stub
return false;
}
public void remove() throws RemoveException {
// TODO Auto-generated method stub
}
}
servlet:
import java.io.IOException;
import javax.ejb.EJB;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import pack.Demo;
import pack.DemoRemote;
/**
* Servlet implementation class Client
*/
public class Client extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Client() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
@EJB
DemoRemote rem = new Demo();
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.getWriter().print(rem.disp("World"));
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}
这是项目的结构:
测试
TestEJB
----包
----------Demo.java
----------DemoRemote.java
TestWeb
---- Java资源
--------- SRC
---------------(默认包)
----------------------Client.java
当我在Server上运行Client.java时,它返回:
错误500 - 内部服务器错误
java.lang.NoSuchMethodError:在Client.doGet(Client.java:33)处显示 javax.servlet.http.HttpServlet.service(HttpServlet.java:743)at at javax.servlet.http.HttpServlet.service(HttpServlet.java:856)at at weblogic.servlet.internal.StubSecurityHelper $ ServletServiceAction.run(StubSecurityHelper.java:227) 在 weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) 在 weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:283) 在 weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:176) 在 weblogic.servlet.internal.WebAppServletContext $ ServletInvocationAction.run(WebAppServletContext.java:3272) 在 weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) 在 weblogic.security.service.SecurityManager.runAs(SecurityManager.java:121) 在 weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2019) 在 weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:1925) 在 weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1394) 在weblogic.work.ExecuteThread.execute(ExecuteThread.java:209)at weblogic.work.ExecuteThread.run(ExecuteThread.java:181)
我正在使用eclipse与WebLogic Server 9.2 + Java EE 5。 有人可以帮我解决这个问题吗 谢谢你的时间。