81,092
社区成员
发帖
与我相关
我的任务
分享
<c:forEach items="${content}" var="content">
<select class="form-control" name="category">
<c:forEach items="${category}" var="category">
<c:if test="${category.id==content.category}">
<option value="${category.id}" selected>${category.title}</option>
</c:if>
</c:forEach>
</select>
</c:forEach>
可是这样写为什么还是只显示一个呢?就显示了文章归属的分类,其他的不显示
<c:forEach items="${content}" var="content">
<select class="form-control" name="category">
<c:forEach items="${category}" var="category">
<c:if test="${category.id==content.category}">
<option value="${category.id}" selected>${category.title}</option>
</c:if>
</c:forEach>
</select>
</c:forEach>
可是这样写为什么还是只显示一个呢?就显示了文章归属的分类,其他的不显示
[/quote]
<c:forEach items="${contents}" var="content">
<select class="form-control" name="category">
<c:forEach items="${categorys}" var="category">
<c:if test="${category.id==content.category}">
<option value="${category.id}" selected>${category.title}</option>
</c:if>
<c:if test="${category.id!=content.category}">
<option value="${category.id}">${category.title}</option>
</c:if>
</c:forEach>
</select>
</c:forEach>
1.循环逻辑明显 有问题。
2.forEach要注意items和var的含义,items是后台放置到request里面的集合对象,var是遍历时候每个分量,不能和items一样的。
<select >
<%for(int i=0;item.length;i++){%>
<option value=''<%=item.get(i).id%>" <% if(item.get(i).equals("java")){%>selected<%}%>><%=item.get(i).name%><option>
<% }%>
</select >
<select >
<%for(int i=0;item.length;i++){%>
<option value=''<%=item.get(i).id%>"><%=item.get(i).name%><option>
<% }%>
</select >
这样不就可以吗?