首页 > 代码库 > JSTL和select标签的组合使用

JSTL和select标签的组合使用

1.用于根据不同的值显示对应的内容,不能选择

<select name="grade">
<c:choose>
    <c:when test="${grade == ‘A‘}">
        <option value="A" selected>A</option>
    </c:when>
    <c:when test="${grade == ‘B‘}">
        <option value="B" selected>B</option>
    </c:when>
    <c:when test="${grade == ‘C‘}">
        <option value="C" selected>C</option>
    </c:when>
</c:choose>
</select>        

 

2.用于根据值设置select的默认选项,可以选择

<select name="grade">
    <option value="A" <c:if test="${grade==‘A‘}">selected</c:if>>A</option>
    <option value="B" <c:if test="${grade==‘B‘}">selected</c:if>>B</option>
    <option value="C" <c:if test="${grade==‘C‘}">selected</c:if>>C</option>
</select>