//Class中
List list= new ArrayList();
ResultSet r = stmt.executeQuery("SELECT a, b FROM Table1");
while (r.next())
{
Map map=new HashMap();
int i = r.getInt("a");
map.put("a",i);
String s = r.getString("b");
map.put("s",s);
list.add(map);
}
request.setAttribute("list",list);//JSP页面中:<html:optionsCollection property="list"
value="a"
label="s"/>
</html:select>
List list= new ArrayList();
ResultSet r = stmt.executeQuery("SELECT a, b FROM Table1");
while (r.next())
{
Map map=new HashMap();
int i = r.getInt("a");
map.put("a",i);
String s = r.getString("b");
map.put("s",s);
list.add(map);
}
request.setAttribute("list",list);//JSP页面中:<html:optionsCollection property="list"
value="a"
label="s"/>
</html:select>
解决方案 »
- 关于select标签传多个值问题
- 各位大侠们,请问Jsp实现日志系统,发表文章的时候,预览功能如何实现,最好将一下思路和帖一下代码。
- servlet的处理
- 求hibernate的中文api 最好是chm的 先谢谢大哥大姐
- Jgraph中图形的拖放
- 帮忙看看,是不是哪里配错了(JBoss 4 sp1部署CMP)?
- 连不到数据库,提示:[Microsoft][SQLServer 2000 Driver for JDBC]End of stream was detected on a read
- 求救,怎样对一个jpg或gif图片文件压缩它的大小
- 请高手给我一个客户端使用ejb的例子,谢谢。
- 来个大牛帮小弟看看,感激不尽!!
- 谁用过wss4j+axis2+usertoken 做过东西,给个例子呗,谢谢
- 100分求ajax4jsf.zip
import org.apache.struts.util.LabelValueBean;
public ArrayList getGathering_Type_List(String org_idx) throws Exception{
ArrayList list = new ArrayList();
String sql = "select idx_no,e_title from Gathering_Type where order by idx_no";
Connection conn = null;
Statement stmt = null;
ResultSet rs = null;
try{
conn = ConnectionUtils.currentConnection();
stmt = conn.createStatement();
rs = stmt.executeQuery(sql);
while(rs.next()){
String idx_no = rs.getString("idx_no");
String e_title = rs.getString("e_title");
LabelValueBean label = new LabelValueBean(e_title,idx_no);
list.add(label);
}
}catch(Exception e){
throw e;
}
finally{
ConnectionUtils.closeResultSet(rs);
ConnectionUtils.closeStatement(stmt);
}
return list;
}
//struts Action中Gathering_Type_Dao type_Dao=new Gathering_Type_Dao();
ArrayList typeList=type_Dao.getGathering_Type_List(myForm.getOrg_idx());
request.setAttribute("typeList", typeList); //struts jsp中
<html:select property="type_idx" >
<html:options collection="typeList" property="value" labelProperty="label"/>
</html:select>
希望對你有所幫助
STRUTS中的下拉选择列表标签必须嵌套在<html:form>标签中,包括:
1.<html:select>
2.<html:option>
3.<html:options>
4.<html:optionsCollection> 使用时嵌套如下:
<html:select property="ationForm.property">
<html:option>或<html:options>或<html:optionsCollection>
</html:select>
其中property为ActionForm中对应的一个属性. 1.<html:option>
<html:option value="value">displayName</html:option>
其中value为实际使用的值(赋值到ActionForm对应的属性中) displayName页面中显示的信息.
例:<html:option value=""></html:option>显示一个空白选择,值为"". 2..<html:options>
<html:options collection="collection" labelProperty="displayName" property="value"/>
其中collection为一个集合,一般是个ArrayList,displayName为前台显示的名称,value为后台实际使用的值.
例:<html:options collection="arrayList" labelProperty="name" property="id" /> 3..<html:optionsCollection>
<html:optionsCollection property="actionForm.property" label="displayName" value="value"/>
其中property为ActionForm中的一个属性,为一个集合.displayName为前台显示的名称,value为后台实际使用的值.
例:<html:optionsCollection property="listProperty" label="name" value="id" /> 补充一点:如果要从 数据库去取数据,一般是在 action 里调用 DAO ,把结果存入一个ArrayList作为 request 的一个属性传到页面上; 这时一般用 <html:options .../> 标签.另外,如果数据不从数据库去取,而是代码固定的,则一般把这种放到 ActionForm 里,作为属性在页面上取,这时一般用 <html:optionsCollection ... />