后台:搜索数据放入list,然后为这个list提供响应的get和set方法
private List<String> l=new ArrayList<String>();
public List<String> getL() {
return l;
}
public void setL(List<String> l) {
this.l = l;
}
//给list赋值的方法,增加一个默认值:请选择,这样下拉列表展现出来的数据好看些
public String configUI(){
//查询所有的车险渠道来源以及名称,放到list然后传递到前台-channelnamelist
l.add("请选择");
l.addAll(Service.getChannelname());
return "configUI";
}
前台接受
渠道来源:<select id="channelname" name="channelname" cssClass="input4">
<c:forEach var="value" items="${L}">
<option value="${value}">
${value}
</option>
</c:forEach>
</select>
</span>
效果图
+20160706+
如果是list中是对象呢?
+20190301+
如果是枚举类型呢?
将枚举转化为map
<select class="select" size="1" style="width: 100%;"name="merchantStatus" id="merchantStatus" required>
<c:forEach var="value" items="${merchantStatusMap}">
<option value="${value.key}">
${value.value}
</option>
</c:forEach>
</select>
如果还有默认值,则增加一个判断
<select class="select" size="1" style="width: 100%;"name="merchantType" id="merchantType" required>
<c:forEach var="value" items="${merchantTypeMap}">
<c:choose>
<c:when test="${m.merchantType==value.key}">
<option value="${value.key}" selected="true">
${value.value}
</option>
</c:when>
<c:otherwise>
<option value="${value.key}">
${value.value}
</option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
+20190313+c:forEach checkbox
页面选项-后端提供可选项
<c:forEach items="${theMap}" var="value">
<lable><input name="theType" type="checkbox" value="${value.key}" />${value.value.desc}</lable>
</c:forEach>
查看页面-后端提供已选项与可选项-不可修改checkbox
<c:forEach items="${theMap}" var="value">
<lable><input name="theType" type="checkbox" value="${value.key}"
<c:forEach items="${theMapCheckBox}" var="v2">
<c:if test="${v2==value.key}"> checked="true" </c:if>
</c:forEach>
onclick="return false" />${value.value.desc}</lable>
</c:forEach>
编辑页面
<c:forEach items="${theMap}" var="value">
<lable><input name="theType" type="checkbox" value="${value.key}"
<c:forEach items="${theMapCheckBox}" var="v2">
<c:if test="${v2==value.key}"> checked="true" </c:if>
</c:forEach>
onclick="return false" />${value.value.desc}</lable>
</c:forEach>