struts的html:select问题,谁解决了100分
为了从数据库中读取值显示到下拉列表框中
我是这样实现的
我写了一个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中值不是显示传过去的值,而是显示下拉列表框中的第一个值。这个问题怎么解决呢