我想在jsp页面上用下拉框显示出从数据库中查询出来的机构名称首先定义了类
public class BrchInfo {private String brchCode; //机构代码
private String brchName; //机构名称public BrchInfo(){}public BrchInfo(String brchCode,String brchName){
this.brchCode=brchCode;
this.brchName=brchName;
}public String getBrchCode() {
return brchCode;
}
public void setBrchCode(String brchCode) {
this.brchCode = brchCode;
}
public String getBrchName() {
return brchName;
}
public void setBrchName(String brchName) {
this.brchName = brchName;
}
}
=============================================
然后在action里这样做了
private ActionForward doInit(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {ArrayList tmpList=new ArrayList();try { 
这里进行数据库连接,代码略String sql = "select brch_no,brch_name from tab_brch_info";
ResultSet rs =null;
执行数据库查询,while(rs.next()){
BrchInfo tmpForm=new BrchInfo();
tmpForm.setBrchCode(rs.getString("brch_no"));
tmpForm.setBrchName(rs.getString("brch_name"));
tmpList.add(tmpForm);}
request.setAttribute("tmpList", tmpList); 
}catch (Exception e) {}======================================
JSP页面中如下:<tr>
<td   >机构:</td>
<td class="tab_td" width="100">
<html:select property="brchCode">
<html:options collection="tmpList" property="brchCode" labelProperty="brchName"></html:options> </html:select>
</td>
</tr>
---------------------------------------------------------
可就是不能出来,页面上啥子都没有,连 [color=#FF0000]机构:[/color]都没出现,删除
html:select property="brchCode">
<html:options collection="tmpList" property="brchCode" labelProperty="brchName"></html:options> [/b]</html:select>就正常,请问是哪里问题

解决方案 »

  1.   

    下拉菜单取值取Select里的property="brchCode">,貌似你有重名的。。
      

  2.   

     <logic:iterate id="" name="" property="allList" indexId="index">      
    <option value="> <bean:write name="" property="" /> </option>
    </logic:iterate>
    用logic标签。。遍历你的list集合
      

  3.   

    确实会自己循环。。
    <select style="width: 55;" id="pagebox" onchange="javascript:gotoPage(this.value)"></select>
    可是要JS脚步的。。
    我分页现在都是打包的
      

  4.   

    看看这个:http://topic.csdn.net/t/20061108/11/5141791.html,貌似你少了个<html:form>我记得要是使用html标签动态获取或传值需要放到<html:form>中使用
      

  5.   

    代码只贴了一段,是放在 <html:form>中的没有报错
      

  6.   

    jsp页面也写个
    <%
    String tmpList= request.getAttribute("tempList");
    %>
      

  7.   

    while(rs.next()){
    BrchInfo tmpForm=new BrchInfo();
    tmpForm.setBrchCode(rs.getString("brch_no"));
    tmpForm.setBrchName(rs.getString("brch_name"));
    tmpList.add(tmpForm);}
    request.setAttribute("tmpList", tmpList); 
    测试下,你这个list能不能传入页面吧!。。如果你页面显示是空白的话
      

  8.   

    把 <html:select property="brchCode">
    <html:options collection="tmpList" property="brchCode" labelProperty="brchName"></html:options>
    </html:select>
    这段删了,才能显示 其他元素
    加上什么都不显示,好奇怪
      

  9.   

    while(rs.next()){
    BrchInfo tmpForm=new BrchInfo();
    tmpForm.setBrchCode(rs.getString("brch_no"));
    tmpForm.setBrchName(rs.getString("brch_name"));
    tmpList.add(tmpForm);}
    不是说后台,你在前台页面用JS加载的时候就打印提示框看看,得到是什么?【object】还是未识别对象
      

  10.   

    把tmpList改为SelectItem类型试一下