jsp中用java代码拼接下拉选备选项及默认值【我】
<th id="TD_N_CERTIFICATION_TYPE" >证件类型:</th> <td > <select id="CERTIFICATION_TYPE" name="CERTIFICATION_TYPE" size="1" class="select156"> <option value="">请选择</option> <% Map voMap = (Map) request.getAttribute("voMap");<!-- EL中的voMap,就是一个变量map --> List optionsList = (List)request.getAttribute("optionsList");<!-- 获取备选项集合,相当于EL的${optionsList}" --> if(optionsList != null && optionsList.size()>0) { <!-- 遍历拼接备选项 --> for(int i =0;i<optionsList.size();i++) { Map mapType = (Map) optionsList.get(i); String code = mapType.get("ATTR_VALUE_CODE").toString(); String name = (String)mapType.get("ATTR_VALUE_NAME"); String defaultValue = (String) voMap.get("CERTIFICATION_TYPE"); if (code.equals(defaultValue)) {<!-- 设置默认备选项为选中状态 --> %> <option value='<%=code%>' selected="selected"> <%=name%> </option> <% } else { %> <option value='<%=code%>'> <%=name%> </option> <% } } } %> </select> </td>