jsp頁面需要有語句<%@ taglib uri=" http://java.sun.com/jstl/core" prefix="c" %> 工程中需要導入jstl的jar包
1.單個變量型(有預設值)
<select name="end_time_year">
<c:choose>
<c:when test="${a_year == '2007'}">
<option value="2007" selected>2007</option>
</c:when>
<c:otherwise>
<option value="2007">2007</option>
</c:otherwise>
</c:choose>
<c:choose>
<c:when test="${a_year == '2008'}">
<option value="2008" selected>2008</option>
</c:when>
<c:otherwise>
<option value="2008">2008</option>
</c:otherwise>
</c:choose>
</select>
注: 其中a_year是從背景傳過來的。如果傳過來的值是2007,則選擇下拉框中2007預設被選中。 2.周遊list(有預設值) <select name="type">
<logic:iterate id="type2" name="type2List" scope="request">
<c:choose>
<c:when test="${type2 == a_fault_type}">
<option value="<c:out value="${a_fault_type}"/>" selected><c:out value="${a_fault_type}"/></option>
</c:when>
<c:otherwise>
<option value="<c:out value="${type2}"/>"><c:out value="${type2}"/></option>
</c:otherwise>
</c:choose>
</logic:iterate>
</select> 注:name="type2List" scope="request"表示從背景action中通過request的方式傳值。
<c:choose> <c:when>
</c:when>
<c:otherwise>
</c:otherwise>
</c:choose>
可以了解為
if(){
}else{
} 3.周遊list(無預設值) <select name="type">
<logic:iterate id="type2" name="type2List" scope="request">
<option value="<c:out value="${type2}"/>"><c:out value="${type2}"/></option>
</logic:iterate>
</select>