struts的html:select问题,谁解决了100分

qjhaaaaa 2003-10-15 04:37:49
为了从数据库中读取值显示到下拉列表框中
我是这样实现的
我写了一个bean
package com.zzcq.stationsrv.system.trainhead;

/**
*
* <p>Title: </p>
* <p>Description: </p>
* <p>Copyright: Copyright (c) 2003</p>
* <p>Company:zzcq </p>
* @author qinjianhua
* @version 1.0
*/

public class DeptNameBean {

private int id; //机务段名称ID
private String description; //机务段描述即机务段名称

public DeptNameBean() {
}
/**
* 显示所属机务段名称
* @param id 机务段名称id
* @param description 机务段名称描述
*/
public DeptNameBean( int id, String description ) {
this.id = id;
this.description = description;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}

然后我在action中这样写的
public Collection showDeptName() throws Exception{
//连接数据库
getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
String sql = null;
ArrayList arrayList = new ArrayList();
try{
sql = "select distinct * from Btbl_OrganizationInfo order by DeptName";
ps = conn.prepareStatement(sql);
rs = ps.executeQuery();
while(rs.next()){
//调用DeptNameBean
arrayList.add(new DeptNameBean(rs.getInt("OrganizationID"),rs.getString("DeptName")));

}
}catch(Exception ex){
System.out.println("error call showDeptName():" + ex.getMessage());
}finally{
//释放数据库连接
if(conn != null) conn.close();
if(ps != null) ps.close();
if(rs != null) rs.close();
}
//返回结果
return arrayList;
}

我在execute方法中
//显示所属机务段名称
Collection DeptName = showDeptName();
HttpSession session = httpServletRequest.getSession();
session.setAttribute("deptName",DeptName);

//显示车头类型名称
Collection HeaderTypeName = showHeaderTypeName();
session.setAttribute("headerTypeName",HeaderTypeName);

在jsp页面上的标签如下
<html:select name ="trainHeadForm" property="deptName" style="width:160" >
<html:options collection ="deptName" property ="id" labelProperty ="description" />
</html:select>

就实现了显示下拉列表框的问题
现在我有一个问题
在一个主页面例如trainHeadMain.jsp中
有一个列表显示出数据库中表中的所有数据
我点击一个按钮,将列表中的值传到修改页面
updateTrainHead.jsp,所有的值是传过去的
text中能显示传过去的值,但是html:select中值不是显示传过去的值,而是显示下拉列表框中的第一个值。这个问题怎么解决呢
...全文
91 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
VVV_lucky 2004-03-08
  • 打赏
  • 举报
回复
假如没有人,你自己可以删了。
qjhaaaaa 2004-03-08
  • 打赏
  • 举报
回复
没有人回答怎么揭帖
steven760812 2004-03-08
  • 打赏
  • 举报
回复
在ACTION中将
arrayList.add(new DeptNameBean(rs.getInt("OrganizationID"),rs.getString("DeptName")));
改为:(LabelValueBean将自动将数据变为SELECT所需的内容)
arrayList.add(new LabelValueBean(rs.getString("DeptName"), rs.getInt("OrganizationID"));
在显示页面写成类似如下:
html:select 中的name为整个页面的信息的arrayList,
<html:select property="bank_id" name="bankinfo">
<html:option value="" key="error.book.page"/>
<html:options collection="banklist" labelProperty="label" property="value"/>
</html:select>
Leemaasn 2004-03-08
  • 打赏
  • 举报
回复
還是我來回答,,
順便蹭點分吧。。。

67,512

社区成员

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

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