如何从两个数组列表中列出选择框中的所有描述

时间:2014-07-14 01:55:59

标签: java arrays jsp

对不起我刚接触JSP,我试图通过组合两个数组列表描述列出选择框中的所有描述,但我失败了。感谢您的帮助。

-------------------JSP -----------------------------
     ArrayList alRiskFactor = new ArrayList();
     ArrayList exRiskFactor = new ArrayList();
    SQL = "SELECT A.CODE,A.DESCP FROM TB_RISKFACTOR A, TB_TR_MAINRULE B WHERE A.CODE=B.RFACTOR AND B.UKEY='"+TARIFFTYPE+"' AND A.TYPE='TR' WITH UR";
    DB_Tariff.executeQuery(SQL);    
    while(DB_Tariff.getNextQuery()){
        ArrayList alInner   = new ArrayList();
        String code     = common.setNullToString(DB_Tariff.getColumnString("CODE"));
        String descp    = common.setNullToString(DB_Tariff.getColumnString("DESCP"));

        alInner.add(code);
        alInner.add(descp);         
        alRiskFactor.add(alInner);
    }
    SQL = "SELECT A.CODE,A.DESCP FROM TB_RISK_FACTOR_SETUP A, TB_TR_MAINRULE B WHERE A.CODE=B.RFACTOR AND B.UKEY='"+TARIFFTYPE+"' WITH UR";
    DB_Tariff.executeQuery(SQL);    
    while(DB_Tariff.getNextQuery()){
        ArrayList alInner   = new ArrayList();
        String code     = common.setNullToString(DB_Tariff.getColumnString("CODE"));
        String descp    = common.setNullToString(DB_Tariff.getColumnString("DESCP"));

        alInner.add(code);
        alInner.add(descp);         
        exRiskFactor.add(alInner);
    }

下面是我目前正在做的事情,我正在尝试将两个数组列表结合起来列出所有描述。然而,它只显示第二个阵列描述。

------------------------------HTML--------------------------

 <select name="RISKFACTOR" style="width: 300px;" onchange="fnReload('F');">
         <option value="" selected>Select Tariff Type</option>
         <%for(Iterator i = alRiskFactor.iterator(); i.hasNext();){
          ArrayList alInner = (ArrayList) i.next();
          String code       = (String) alInner.get(0);
          String descp      = (String) alInner.get(1);

         %>
          <%for(Iterator e = exRiskFactor.iterator(); i.hasNext();){
           alInner  = (ArrayList) e.next();
           code     = (String) alInner.get(0);
           descp        = (String) alInner.get(1);

         %>
          <option value="<%=code%>" <%= code.equals(RISKFACTOR)?"selected":"" %>><%=descp%></option>
         <%}}%>
</select>            

1 个答案:

答案 0 :(得分:0)

您的问题似乎是您只在第二个列表的循环内创建option元素。试试这段代码:

------------------------------HTML--------------------------

<select name="RISKFACTOR" style="width: 300px;" onchange="fnReload('F');">
    <option value="" selected>Select Tariff Type</option>
    <%for(Iterator i = alRiskFactor.iterator(); i.hasNext();) {
        ArrayList alInner = (ArrayList) i.next();
        String code       = (String) alInner.get(0);
        String descp      = (String) alInner.get(1);

    %>
    <option value="<%=code%>" <%= code.equals(RISKFACTOR)?"selected":"" %>><%=descp%></option>
    <%}%>
    <%for(Iterator e = exRiskFactor.iterator(); i.hasNext();) {
        alInner  = (ArrayList) e.next();
        code     = (String) alInner.get(0);
        descp        = (String) alInner.get(1);

    %>
    <option value="<%=code%>" <%= code.equals(RISKFACTOR)?"selected":"" %>><%=descp%></option>
    <%}%>
</select>