0
我有低於這個函數從Oracle數據庫拉數據的JavaBean的名稱FanBean有困難從Oracle數據庫中提取數據,JavaBean和JSP
public java.util.Vector getList() {
java.util.Vector myFanList = new java.util.Vector();
StringBuffer sql = new StringBuffer();
DbUtil db = null;
ResultSet rset = null;
db = new DbUtil();
sql.append(" SELECT id_no, name");
if ((this.getSelectedFanType() != null)&& (this.getSelectedFanType().equals("1"))){
sql.append(" from my_fan ");
}
if ((this.getSelectedFanType() != null)&& (this.getSelectedFanType().equals("2"))){
sql.append(" from my_fan ");
sql.append(" where id_no = '");
sql.append(this.getSearchVar());
sql.append("'");
}
if ((this.getSelectedFanType() != null)&& (this.getSelectedFanType().equals("3"))){
sql.append(" from my_fan ");
sql.append(" where name = '");
sql.append(this.getSearchVar());
sql.append("'");
}
if (this.getSelectedSort() != null) {
if(this.getSelectedSort().equals("1"))
sql.append(" ORDER BY id_no");
else if(this.getSelectedSort().equals("2"))
sql.append(" ORDER BY name");
else
sql.append(" ORDER BY id_no");
} else
sql.append(" ORDER BY id_no");
rset = db.executeQuery(sql.toString(),true);
if (rset != null) {
while(rset.next()) {
FanBean myFan = new FanBean();
myFan.setIdNo(rset.getString(1).trim());
myFan.setName(rset.getString(2));
myFanList.addElement(myFan);
Enumeration e = myFanList.elements();
while (e.hasMoreElements()) {
FanBean nextFan = (FanBean) e.nextElement();
this.addDtlItem(nextFan.getIdNo(), nextFan.getName());
}
}
}
}
return myFanList;
}
我有這個功能,增加了數據FanItemBean的java bean
public void addDtlItem(String idNo, String name)
{
FanItemBean detailItem = new FanItemBean(idNo, name);
_dtlListArray.add(detailItem);
}
最後在jsp中我拉了數據這樣
<%
Collection dtlItems = fanBean.getDetailItems();
Iterator it = dtlItems.iterator();
int i = 0;
String colorStr = null;
while(it.hasNext()){
FanItemBean fanDtlItem = (FanItemBean) it.next();
%>
<TR>
<TD><%= fanDtlItem.getIdNo()%></TD>
<TD><%= fanDtlItem.getName()%></TD>
</TR>
<%
i++;
} %>
有人能告訴我在這個循環中我做錯了什麼,我沒有在jsp頁面中獲取任何數據。謝謝
只是檢查,但你確定你的JSP的作品?它看起來像在你的JSP腳本中,你正在爲while循環缺少一個閉合的「}」(假設你直接從你的JSP中拷貝了這個,我確信這會導致一個問題)。 – brent777
哦對不起,我忘了添加它..我有.. – Jack
你在哪裏添加bean到你的請求上下文?你使用servlet嗎? – home