Y
youweibin
Unregistered / Unconfirmed
GUEST, unregistred user!
在一个实体Bean中,有一个ejbFindAll方法,返回类型是Collection,用来返回所有的用户信息,Collection里面存放的是UserInfoDTO值对象。
下面是方法的实现:
public Collection ejbFindAll()
throws FinderException
{
String sql = "SELECT * FROM Users";
DBFactory dbFactory = null;
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
Collection result = new ArrayList();
try
{
dbFactory = DBFactory.getInstance();
conn = dbFactory.getConnection();
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next())
{
UserInfoDTO userInfo = new UserInfoDTO();
userInfo.setID(rs.getInt("UserID"));
userInfo.setName(rs.getString("UserName"));
userInfo.setPassword(rs.getString("UserName"));
userInfo.setEMail(rs.getString("EMail"));
userInfo.setTrueName(rs.getString("TrueName"));
userInfo.setAddress(rs.getString("Address"));
userInfo.setPostCode(rs.getString("PostCode"));
userInfo.setPhone(rs.getString("Phone"));
result.add(userInfo);
}
}
catch (Exception ex)
{
throw new FinderException(ex.getMessage());
}
finally
{
if (dbFactory != null) dbFactory.closeAll(rs, stmt, conn);
}
return result;
}
下面是jsp中的调用:
<%!
Collection users;
%>
<%
try
{
InitialContext ic = new InitialContext();
Object homeRef = ic.lookup("UserAccount");
UserAccountRemoteHome home = (UserAccountRemoteHome)PortableRemoteObject.narrow(homeRef, UserAccountRemoteHome.class);
users = home.findAll();
}
catch (Exception ex)
{
out.println(ex.getMessage());
}
%>
<FORM action="handleDeleteUser.jsp" method="post">
<%
Iterator iterator = users.iterator();
while (iterator.hasNext())
{
out.println(iterator.next().getClass().getName());
//UserInfoDTO userInfo = (UserInfoDTO)iterator.next();
//out.println(userInfo.getName() + "<INPUT type=radio name=UserID value=" + userInfo.getID() + " checked><P>");
}
%>
<INPUT type="submit" name="submit" value="删 除">
</FORM>
当运行该jsp文件时,出现ClassCastException,
我用out.println(iterator.next().getClass().getName())把类名输出后,发出类名是“com.rainbowsoft.bookstore.businesslogic.UserAccount_puqaog_EOImpl_811_WLStub ”,这是怎么回事?
我是用JBuilderX开发的EJB,AppServer使用WebLogic8.1
下面是方法的实现:
public Collection ejbFindAll()
throws FinderException
{
String sql = "SELECT * FROM Users";
DBFactory dbFactory = null;
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
Collection result = new ArrayList();
try
{
dbFactory = DBFactory.getInstance();
conn = dbFactory.getConnection();
stmt = conn.prepareStatement(sql);
rs = stmt.executeQuery();
while (rs.next())
{
UserInfoDTO userInfo = new UserInfoDTO();
userInfo.setID(rs.getInt("UserID"));
userInfo.setName(rs.getString("UserName"));
userInfo.setPassword(rs.getString("UserName"));
userInfo.setEMail(rs.getString("EMail"));
userInfo.setTrueName(rs.getString("TrueName"));
userInfo.setAddress(rs.getString("Address"));
userInfo.setPostCode(rs.getString("PostCode"));
userInfo.setPhone(rs.getString("Phone"));
result.add(userInfo);
}
}
catch (Exception ex)
{
throw new FinderException(ex.getMessage());
}
finally
{
if (dbFactory != null) dbFactory.closeAll(rs, stmt, conn);
}
return result;
}
下面是jsp中的调用:
<%!
Collection users;
%>
<%
try
{
InitialContext ic = new InitialContext();
Object homeRef = ic.lookup("UserAccount");
UserAccountRemoteHome home = (UserAccountRemoteHome)PortableRemoteObject.narrow(homeRef, UserAccountRemoteHome.class);
users = home.findAll();
}
catch (Exception ex)
{
out.println(ex.getMessage());
}
%>
<FORM action="handleDeleteUser.jsp" method="post">
<%
Iterator iterator = users.iterator();
while (iterator.hasNext())
{
out.println(iterator.next().getClass().getName());
//UserInfoDTO userInfo = (UserInfoDTO)iterator.next();
//out.println(userInfo.getName() + "<INPUT type=radio name=UserID value=" + userInfo.getID() + " checked><P>");
}
%>
<INPUT type="submit" name="submit" value="删 除">
</FORM>
当运行该jsp文件时,出现ClassCastException,
我用out.println(iterator.next().getClass().getName())把类名输出后,发出类名是“com.rainbowsoft.bookstore.businesslogic.UserAccount_puqaog_EOImpl_811_WLStub ”,这是怎么回事?
我是用JBuilderX开发的EJB,AppServer使用WebLogic8.1