Servlet和Session之间Collecion的传递问题,急~~~~在线等555....

Sundery 2003-08-20 02:18:34
SessionBean:

public java.util.Collection listalluser() {
customHome home = null;
try
{
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");

Context ctx = new InitialContext(env);
home = (customHome) ctx.lookup("custom");

return home.findAllUser();
//home.findAllUser()是CMP的方法,返回类型:java.util.Collecion

}


然后到Servlet里面:

private void listalluser(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
{
Context ctx = null;
try
{
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY,"weblogic.jndi.WLInitialContextFactory");

ctx = new InitialContext(env);

Object ref = ctx.lookup("customsession");
customsessionHome home = (customsessionHome) PortableRemoteObject.narrow(ref,customsessionHome.class);
customsession session = home.create();

ArrayList alluser = new ArrayList(session.listalluser());
//上面的语句出错:(
//错误代码:<Error><HTTP><101017><[ServletContext(id=5563596,name=soundbox,context-path=/soundbox)]>Root cause of ServletException java.lang.AbstractMethodError at.....
System.out.println("OK ArrayList");

request.getSession().setAttribute("alluser",alluser);
response.sendRedirect("listuser.jsp");

}
...全文
42 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
Morgan_ma 2003-08-24
  • 打赏
  • 举报
回复
蹭分蹭分。。。 :)
vigorlee3 2003-08-24
  • 打赏
  • 举报
回复
男乌贼鱼
给分
对了 你大作业怎么样了?
vigorlee3 2003-08-24
  • 打赏
  • 举报
回复
public Collection ejbFindByAll() throws FinderException {
}

//session bean中对实体bean中的调用:
public Collection findAll() throws RemoteException {
java.util.ArrayList m_return = new java.util.ArrayList() ;
try {
InitialContext initial = new InitialContext();
Object objRefTaxBean = initial.lookup("TaxBean");
TaxHome taxhome = (TaxHome) PortableRemoteObject.narrow(objRefTaxBean,TaxHome.class);
java.util.Collection cl = taxhome.findByAll();
System.out.println("Find end ");
java.util.Iterator it = cl.iterator();
while( it.hasNext()) {
java.util.ArrayList m_item = new java.util.ArrayList() ;
Tax tax = (Tax)it.next();
m_item.add(String.valueOf(tax.getId()));
m_item.add(tax.getName());
m_item.add(tax.getPassword());
m_return.add(m_item);
}
}catch(NamingException e) {
...
}
return m_return ;
}



//jb client
ArrayList arrayList = client.findAll();
System.out.println("id name password");
while(!arrayList.isEmpty()) {
ArrayList array = (ArrayList)arrayList.get(0);
arrayList.remove(0);
System.out.println(array.get(0) + " " + array.get(1) + " " + array.get(2));
}
saviourlee 2003-08-21
  • 打赏
  • 举报
回复

建议使用value object
Sundery 2003-08-21
  • 打赏
  • 举报
回复
我也怀疑可能是这个问题,还有别的可能性吗?
hk2000c 2003-08-21
  • 打赏
  • 举报
回复
你看看你的EntityBean是不是remote的,如果不是,那很可能就是这个原因,把EntityBean的Local属性改成Remote就可以了。不过不建议你直接把Entity的东西暴露给servlet会有安全隐患。可以写一个DataWrapper.把需要的包进去就可以了,也可以用SessionBean来实现。
liad 2003-08-21
  • 打赏
  • 举报
回复
可能是你的JDBC驱动版本问题,没有实现抽象类接口,所以才会抛出java.lang.AbstractMethodError
hk2000c 2003-08-21
  • 打赏
  • 举报
回复
我觉得是EntityBean接口属性问题可能性更大一点,建议楼主不要把EntityBean直接返回到servlet.这样做不太好,换种写法。apache上面有个包是解决这个问题的。个人意见,欢迎讨论。

Morgan_ma 2003-08-21
  • 打赏
  • 举报
回复
他试过了,还是不行。。。 :)


对发?楼主。。。
chenwg168 2003-08-21
  • 打赏
  • 举报
回复
恩,确实是类型不匹配
Collection c=session.listalluser()
Iterator it=c.iterator();
这样试试吧
Sundery 2003-08-21
  • 打赏
  • 举报
回复
对的,我确定有数据
zez 2003-08-21
  • 打赏
  • 举报
回复
session bean 里
return home.findAllUser();
你确定返回的不是null? 这个方法你确定执行正确?确定有数据???
Sundery 2003-08-20
  • 打赏
  • 举报
回复
up
rockrabbit 2003-08-20
  • 打赏
  • 举报
回复
re
Sundery 2003-08-20
  • 打赏
  • 举报
回复
TO: lsy110(毛毛)

确实是:throws SErvletException
但是有什么方法呢?
Sundery 2003-08-20
  • 打赏
  • 举报
回复
up
xmpp 2003-08-20
  • 打赏
  • 举报
回复
Constructs a list containing the elements of the specified collection, in the order they are returned by the collection's iterator.
直接使用
ArrayList alluser = (ArrayList)session.listalluser();看看。
lsy110 2003-08-20
  • 打赏
  • 举报
回复
private void listalluser(HttpServletRequest request, HttpServletResponse response)throws ServletException, IOException
這個方法改個名字看看!粗看看不出什么問題......
lsy110 2003-08-20
  • 打赏
  • 举报
回复
看来应该是session.listalluser()方法的问题了,凭这些信息很难知道哪里有错误了,有没有更详细的信息?
Sundery 2003-08-20
  • 打赏
  • 举报
回复
获得了,

而且,现在即使我放到jsp里面调用,仍旧会有这类的问题
加载更多回复(1)

67,512

社区成员

发帖
与我相关
我的任务
社区描述
J2EE只是Java企业应用。我们需要一个跨J2SE/WEB/EJB的微容器,保护我们的业务核心组件(中间件),以延续它的生命力,而不是依赖J2SE/J2EE版本。
社区管理员
  • Java EE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧