关于数据库取数据并显示到html:select的很难描述的问题
2007-06-13 16:06
731 查看
[问题]
原:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public void parentmsg(ActionForm form, HttpServletRequest request)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DataConn dc=new DataConn();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Connection conn;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
String sql=null;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ArrayList fenleis = new ArrayList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
FenleiForm fenlei= new FenleiForm();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
conn = dc.getConnection();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Statement stmt = conn.createStatement();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sql="select * from fenlei where parid=1";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ResultSet rs=stmt.executeQuery(sql);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
while (rs.next())...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenlei.setLbid(rs.getInt("lbid"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenlei.setLbname(rs.getString("lbname"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(rs.getInt("lbid")); //测试用
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(rs.getString("lbname"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenleis.add(i, fenlei); //这里的fenlei实际是按地址传递的
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
request.setAttribute("lstfenlei", fenleis);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//fenlei.setFenleis(fenleis);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}catch(Exception e)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(e.getMessage());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
lstfenlei的最终结果:
lbid=3 lbname="女童装"
lbid=3 lbname="女童装"
修改后
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public void parentmsg(ActionForm form, HttpServletRequest request)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DataConn dc=new DataConn();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Connection conn;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
String sql=null;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ArrayList fenleis = new ArrayList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
conn = dc.getConnection();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Statement stmt = conn.createStatement();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sql="select * from fenlei where parid=1";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ResultSet rs=stmt.executeQuery(sql);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
while (rs.next())...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
FenleiForm fenlei= new FenleiForm(); //要放在循环里面,用来重新在内存中开辟一块区域存储数据
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenlei.setLbid(rs.getInt("lbid"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenlei.setLbname(rs.getString("lbname"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(rs.getInt("lbid")); //测试用
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(rs.getString("lbname"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenleis.add(i, fenlei); //这里的fenlei实际是按地址传递的
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
request.setAttribute("lstfenlei", fenleis);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//fenlei.setFenleis(fenleis);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}catch(Exception e)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(e.getMessage());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
lstfenlei最终结果:
lbid=2 lbname="男童装"
lbid=3 lbname="女童装"
jsp页面:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html:select property="lbid">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html:option value="0" >--请选择父类别--</html:option>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html:optionsCollection name="lstfenlei" label="lbname" value="lbid" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html:select>
原:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public void parentmsg(ActionForm form, HttpServletRequest request)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DataConn dc=new DataConn();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Connection conn;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
String sql=null;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ArrayList fenleis = new ArrayList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
FenleiForm fenlei= new FenleiForm();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
conn = dc.getConnection();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Statement stmt = conn.createStatement();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sql="select * from fenlei where parid=1";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ResultSet rs=stmt.executeQuery(sql);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
while (rs.next())...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenlei.setLbid(rs.getInt("lbid"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenlei.setLbname(rs.getString("lbname"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(rs.getInt("lbid")); //测试用
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(rs.getString("lbname"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenleis.add(i, fenlei); //这里的fenlei实际是按地址传递的
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
request.setAttribute("lstfenlei", fenleis);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//fenlei.setFenleis(fenleis);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}catch(Exception e)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(e.getMessage());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
lstfenlei的最终结果:
lbid=3 lbname="女童装"
lbid=3 lbname="女童装"
修改后
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedBlock.gif)
public void parentmsg(ActionForm form, HttpServletRequest request)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
DataConn dc=new DataConn();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Connection conn;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
String sql=null;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ArrayList fenleis = new ArrayList();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
try ...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
conn = dc.getConnection();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
Statement stmt = conn.createStatement();
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
sql="select * from fenlei where parid=1";
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
ResultSet rs=stmt.executeQuery(sql);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
int i=0;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
while (rs.next())...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
FenleiForm fenlei= new FenleiForm(); //要放在循环里面,用来重新在内存中开辟一块区域存储数据
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenlei.setLbid(rs.getInt("lbid"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenlei.setLbname(rs.getString("lbname"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(rs.getInt("lbid")); //测试用
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(rs.getString("lbname"));
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
fenleis.add(i, fenlei); //这里的fenlei实际是按地址传递的
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
i++;
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
request.setAttribute("lstfenlei", fenleis);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
//fenlei.setFenleis(fenleis);
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockStart.gif)
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ContractedSubBlock.gif)
}catch(Exception e)...{
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/InBlock.gif)
System.out.println(e.getMessage());
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedSubBlockEnd.gif)
}
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/ExpandedBlockEnd.gif)
}
lstfenlei最终结果:
lbid=2 lbname="男童装"
lbid=3 lbname="女童装"
jsp页面:
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html:select property="lbid">
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html:option value="0" >--请选择父类别--</html:option>
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
<html:optionsCollection name="lstfenlei" label="lbname" value="lbid" />
![](http://images.csdn.net/syntaxhighlighting/OutliningIndicators/None.gif)
</html:select>
相关文章推荐
- 请问关于从网络数据库获取数据 并显示的问题
- 显示数据(从数据库中得到)中的html标签 用于解决数据在前台显示,样式被数据破坏的问题!!css
- MES操作数据库后数据显示的一点小问题,关于DataView的rowfilter
- java jsp struts2标签 从数据库中读取含有html标签的数据显示问题
- <问题解决>数据库date类型数据前端页面显示格式不正确问题
- 关于VS2005中C#代码用F12转到定义时,总是显示从元数据的问题题
- 关于ListView中继承BaseAdapter重写getview的显示重复数据或报转换错误的问题
- ASP.NET网络爬虫小研究 HtmlAgilityPack基础,爬取数据保存在数据库中再显示再自己的网页中
- 关于AJAX访问数据库不能及时获得更新数据的问题
- select从数据库取出数据并显示
- bootstrap-select 动态加载数据不显示的问题
- 关于显示数据时内容过多的问题和动态的tooltip实现
- 关于ViewPager嵌套Fragment,第二次加载数据不显示问题
- 关于ListView显示数据,堆积问题的解决方案!!!
- 关于数据库日期格式显示星期的问题
- 关于往数据库插入汉字时,显示乱码的问题
- Jfinal 连接oracle数据关于数据库大小的问题
- 关于orcale数据库查询一段时间内数据的问题
- C# 关于从数据库取数据,并显示在DataGridView中