我有一个HTML表单用于存储和编辑一组数据。表单中还有一个下拉框。当我打开编辑页面时,我的问题是如何将下拉框的默认值设置为刚从数据库获取的值。目前,我使用JSTL标签通过if条件添加属性"selected"。但如果下拉框中有100个值,执行100次if条件并不是一个好的选择。这是我现在的代码。
<select name="outageType" id="outageType" class="span3">
<option
<c:if test='${operation.type == "Type1"}'>selected="selected"</c:if>
value="Type1">Type1</option>
<option
<c:if test='${operation.type == "Type2"}'>selected="selected"</c:if>
value="Type2">Type2</option>
<option
<c:if test='${operation.type == "Type3"}'>selected="selected"</c:if>
value="Type3">Type3</option>
</select>
如果我有100个值,最好的编码方式是什么?我正在使用带有SQL数据库的JSP/Servlets。