我想要设置默认value= ${theObject2.countryId}
<select id="locationCountry" style="padding-left: 2em" >
<option value="">Country</option>
<c:forEach items="${countrieDetail}" var="theObject" varStatus="theCount">
<option value="${theObject.countryId}" >${theObject.countryName}</option>
</c:forEach>
</select>
答案 0 :(得分:0)
您可以使用HTML selected Attribute。只需比较Id并在匹配时设置它。
示例代码:
<select id="locationCountry" style="padding-left: 2em">
<option value="">Country</option>
<c:forEach items="${countrieDetail}" var="theObject">
<option value="${theObject.countryId}" <c:if test="${theObject.countryId == theObject2.countryId }">selected</c:if>>
${theObject.countryName}
</option>
</c:forEach>
</select>