您可以使用 jstl 条件标记来完成此操作
<c:if test="${empty borough}">
<form:select path="borough">
<form:option value="Staten Island">Staten Island</form:option>
<form:option value="Queens">Queens</form:option>
<form:option value="Brooklyn">Brooklyn</form:option>
<form:option value="Bronx">Bronx</form:option>
<form:option value="Manhattan">Manhattan</form:option>
</form:select>
</c:if>
根据评论:
您可以使用 if else 来实现c:choose
<c:choose>
<c:when test="${empty borough}">
<form:select path="borough">
<form:option value="Staten Island">Staten Island</form:option>
<form:option value="Queens">Queens</form:option>
<form:option value="Brooklyn">Brooklyn</form:option>
<form:option value="Bronx">Bronx</form:option>
<form:option value="Manhattan">Manhattan</form:option>
</form:select>
</c:when>
<c:otherwise>
This is the else block, you can have multiple when clause so it will become if else if else code
</c:otherwise>
</c:choose>
一些文档