当前位置: 代码迷 >> Eclipse >> struts结构中,jsp文件中下拉列表的初始化有关问题
  详细解决方案

struts结构中,jsp文件中下拉列表的初始化有关问题

热度:127   发布时间:2016-04-23 14:41:32.0
struts结构中,jsp文件中下拉列表的初始化问题。
我想把数据库中〔地区表〕中的数据读入html画面上的一个下拉列表中。
在Action中能够读取DB,也可以存放到Form中,但是在jsp文件中,使用 <html:select> </html:select> , <html:option> </html:option> 如何初始化下拉列表,或者使用其他方法。
希望能够有代码。

------解决方案--------------------
<%@ page contentType= "text/html; charset=utf-8 " %>
<%@ page language= "java " %>
<%@ taglib uri= "/WEB-INF/struts-html.tld " prefix= "html " %>
<%@ taglib uri= "/WEB-INF/newcon-tag.tld " prefix= "base " %>
<%@ taglib uri= "/WEB-INF/struts-bean.tld " prefix= "bean " %>

<bean:define id= "getDepList " name= "CQ010Form " property= "depList " type= "java.lang.String[][] "/>

<html:html>
<body >
<html:form action = "/CQ010Action " >
<table width= "750 " border= "0 ">
<tr>
<td width= "2% " class= "MustTxt "> * </td>
<td width= "10% " class= "RecTxt "> 表   名 </td>
<td align= "left ">
<html:select property= "selectDep " size= "1 " >
<%
int listLength = getDepList.length;
for (int i = 0; i < listLength; i++) {
String depNo = getDepList[i][0];
String depNm = getDepList[i][1];
%>
<html:option value= " <%=depNo%> "> <%=depNm%> </html:option>
<%
}
%>
</html:select>
</td>
</tr>
</table>
</html:form>
</body>
</html:html>
------解决方案--------------------
参照:

<html:select property= "plantCode " styleClass= "INPUT_TEXT ">
<option value= " "> </option>
<html:options collection= "PLANT_LIST "labelProperty= "plant "property= "plantCode "/>
</html:select>

或者用logic:iterator循环