값 이동 순서
View ➡ Controller ➡ View
HTML
<select id='season' name='season'>
<option value=''>All</option>
<option value='0'>Spring</option>
<option value='1'>Summer</option>
<option value='2'>Fall</option>
<option value='3'>Winter</option>
</select>
[방법1] 삼항 연산자
<select id='season' name='season'>
<option value=''>All</option>
<option value='0' ${season == '0' ? 'selected="selected"' : ''}>Spring</option>
<option value='1' ${season == '1' ? 'selected="selected"' : ''}>Summer</option>
<option value='2' ${season == '2' ? 'selected="selected"' : ''}>Fall</option>
<option value='3' ${season == '3' ? 'selected="selected"' : ''}>Winter</option>
</select>
[방법2] 삼항 연산자 + JSTL
컨트롤러에서 넘어온 객체가 리스트인 경우
<select id='season' name='season'>
<option value=''>All</option>
<c:forEach items='${resultList}' var='list'>
<option value='${list.listNo}' ${list.listNo == '1' ? 'selected="selected"' : ''}>${list.listName}</option>
</c:forEach>
</select>
[방법3] JSTL
<select id='season' name='season'>
<option value=''>All</option>
<c:forEach items='${resultList}' var='list'>
<option value='${list.listNo}' <c:if test='${list.listNo == "1"}'>selected='selected'</c:if>>${list.listName}</option>
</c:forEach>
</select>
'Backend > Java' 카테고리의 다른 글
[IntelliJ] Interface 만들기 (0) | 2021.12.06 |
---|---|
[Eclipse] Java Build Path에서 Maven Dependencies 없을 때 (0) | 2021.11.22 |
[Java] DAO, DTO, VO (0) | 2021.11.19 |
[Java] About JVM, JRE, JDK (0) | 2021.11.17 |
[Eclipse] Tomcat의 Context path (root) 설정 (0) | 2021.11.08 |
댓글