例1:
<select id="select" style="height:28px" name="categoryId">
<c:forEach items="${categorys}" var="category">
<c:if test="${blog.categoryId==category.id}">
<option value="${category.id }" selected>${category.name }</option>
</c:if>
<c:if test="${!(blog.categoryId==category.id)}">
<option value="${category.id }" >${category.name }</option>
</c:if>
</c:forEach>
</select>
备注:例如 传到前台blog和categorys
其中blog有所属分类的id,所有分类都有id。两者相等时,显出当前分类
例2:性别下拉
默认数据库中 1是男,0时女;
<select style="width:100px;">
<c:if test="${user.gender==1}">
<option value="1">男</option>>
</c:if>
<c:if test="${!(user.gender==1)}">
<option value="0">女</option>
</c:if>
</select>
此处注意下拉框的样式修改