我用的没有问题的,在WSAD开发,打包成EAR文件,在WAS中配置,一切OK的
可能是你在JSP中调用SESSION的方法,有问题吧?
还有,可能是在配置过程中出来的EJB的JNDI的名称和你调用的不否和巴
我用的调用EJB的方法:
/**
* 连接EJB,产生remote对象
*/
private boolean ConnEjb() {
try {
javax.naming.Context ctx = new javax.naming.InitialContext();
InitialContext cntxt = new InitialContext();
Object ref = cntxt.lookup("ejb/logs");
loginHome =
(LogSHome) PortableRemoteObject.narrow(ref, LogSHome.class);
theLogEJB = loginHome.create();
return true;
} catch (Exception e) {
System.out.println("控制层连接ejb出错:" + e.getMessage());
return false;
}
}
可能是你在JSP中调用SESSION的方法,有问题吧?
还有,可能是在配置过程中出来的EJB的JNDI的名称和你调用的不否和巴
我用的调用EJB的方法:
/**
* 连接EJB,产生remote对象
*/
private boolean ConnEjb() {
try {
javax.naming.Context ctx = new javax.naming.InitialContext();
InitialContext cntxt = new InitialContext();
Object ref = cntxt.lookup("ejb/logs");
loginHome =
(LogSHome) PortableRemoteObject.narrow(ref, LogSHome.class);
theLogEJB = loginHome.create();
return true;
} catch (Exception e) {
System.out.println("控制层连接ejb出错:" + e.getMessage());
return false;
}
}
解决方案 »
- java 构造函数的问题
- 关于Struts2的Action类
- springframework Order 该怎么理解?
- Hibernate大小写的问题
- [Fatal Error] :1:8: The processing instruction target matching "[xX][mM][lL]" is not allowed.
- hibernate多对多存储关系表报错,查了好久都没有解决!!
- 关于在标签中调用spring的bean的问题
- 帮我看看是什么问题,晕死了,谢谢大家
- 连接池容量问题
- 怎么理解sessionbean和entitybean的生命周期?
- 我做了个简单的EJB应用,运行出现这个异常,散分求教!!!
- 简直让人难以忍受,用entity bean cmp 时,能插入,却不能用findByPrimaryKey()查询
出现的异常如下:
java.rmi.ServerException: RemoteException occurred in server thread; nested exception is: com.ibm.ejs.container.UncheckedException: ; nested exception is: java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBObject_Stub com.ibm.ejs.container.UncheckedException: ; nested exception is: java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBObject_Stub java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBObject_Stub
在was的控制台里显示的是:
CNTR0020E:在 bean BeanId(shop#ShopEJB.jar#BookFacade, null) 上处理方法 inquireByIsnew 时发生非应用程序异常:java.lang.ClassCastException: org.omg.stub.javax.ejb._EJBObject_Stub at shop.ejb.book.BookFacadeBean.inquireByIsnew(BookFacadeBean.java:196) at shop.ejb.book.EJSRemoteStatelessBookFacade.inquireByIsnew(EJSRemoteStatelessBookFacade.java:193) at shop.ejb.book._BookFacade_Stub.inquireByIsnew(_BookFacade_Stub.java:496)
Test.java:
package testdemo;import javax.ejb.*;
import java.util.*;
import java.rmi.*;public interface Test extends javax.ejb.EJBObject
{
public String Hello(String par) throws RemoteException;
}TestBean.java:
package testdemo;import javax.ejb.*;public class TestBean implements SessionBean
{
SessionContext sessionContext;
public void ejbCreate() throws CreateException {
/**@todo Complete this method*/
}
public void ejbRemove()
{
/**@todo Complete this method*/
}
public void ejbActivate()
{
/**@todo Complete this method*/
}
public void ejbPassivate()
{
/**@todo Complete this method*/
}
public void setSessionContext(SessionContext sessionContext)
{
this.sessionContext = sessionContext;
}
public String Hello(String par)
{
/**@todo Complete this method*/
return "Hello, " + par;
}
}TestHome.java:
package testdemo;import javax.ejb.*;
import java.util.*;
import java.rmi.*;public interface TestHome extends javax.ejb.EJBHome
{
public Test create() throws CreateException, RemoteException;
}TestJspBean.java:
package testdemo;import javax.naming.*;
import javax.rmi.*;
import java.rmi.*;
import javax.ejb.*;
import java.util.*;
import testdemo.*;public class TestJspBean
{
private TestHome testHome = null; //Construct the EJB test client
public TestJspBean()
{
initialize();
} public void initialize()
{
try
{
//get naming context
Context context = getInitialContext(); //look up jndi name
Object ref = context.lookup("Test");
//look up jndi name and cast to Home interface
testHome = (TestHome) PortableRemoteObject.narrow(ref, TestHome.class);
}
catch(Exception e)
{
e.printStackTrace();
}
} private Context getInitialContext() throws Exception
{
String url = "t3://cne5:7001";
String user = null;
String password = null;
Properties properties = null;
try
{
properties = new Properties();
properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
properties.put(Context.PROVIDER_URL, url);
if(user != null)
{
properties.put(Context.SECURITY_PRINCIPAL, user);
properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password);
} return new InitialContext(properties);
}
catch(Exception e)
{
System.out.println("Unable to connect to WebLogic server at " + url);
System.out.println("Please make sure that the server is running.");
throw e;
}
} public TestHome getHome()
{
return testHome;
} public String test()
{
try
{
Test remote = getHome().create();
String str = remote.Hello("Jason!");
return str;
}
catch(RemoteException ex)
{
ex.printStackTrace();
}
catch(CreateException ex)
{
ex.printStackTrace();
}
return null;
}
}Test.jsp:
<%@ page contentType="text/html; charset=GBK" %>
<html>
<head>
<title>
TestJsp
</title>
</head>
<jsp:useBean id="test" scope="session" class="testdemo.TestJspBean" />
<jsp:setProperty name="test" property="*" />
<body bgcolor="#ffffff">
<h1>
<%= test.test() %>
</h1>
</body>
</html>
例如:(一个小例子)
Vector vec = null; //这里的vec不能这样写的
if(true) //我是假设你返回的为vec的
return vec;