JSTL 实现 为Select赋多个值

时间:2021-07-23 15:06:12
需要注意需要在.jsp文件中引入相应的类库
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>

<select id="rights" name="rights" multiple="multiple"> <c:forEach items="${tqListAll}" var="tq"> <c:set var="isContains" value="${fn:contains(tqListSelected,tq.id)}" /> <c:choose> <c:when test="${isContains}"> <option value=${tq.id} selected="selected">${tq.name}</option> </c:when> <c:otherwise> <option value=${tq.id}>${tq.name}</option> </c:otherwise> </c:choose> </c:forEach> </select>