示例部分代碼如下:
<select name="pushType" id="pushType" class="liebiao" style="width:100px;" οnchange="changeType(this.value);">
<c:forEach var="codeItem" items="${bean.codeItemList}">
<c:choose>
<c:when test="${codeItem.id == type}">
<option value="<c:out value="${codeItem.id}" />" selected="selected" /><c:out value="${codeItem.item_name}" /></option>
</c:when>
<c:otherwise>
<option value="<c:out value="${codeItem.id}" />" /><c:out value="${codeItem.item_name}" /></option>
</c:otherwise>
</c:choose>
</c:forEach>
</select>
其中<c:when test="${codeItem.id == type}">中codeItem是從後臺傳過來的,type亦是從後臺中一個對象獲取的,在前面有定義如下:
String type = StringUtil.trim(map.get("type"));
然後就是總是報錯,因爲type值那樣寫EL表達式無法取到。
這是網上看到的一個回覆如下:el的內容無非就是在jsp的那個內置範圍對象裏的值。page,request,session,application,pageContext,用這些對象就可以取到el的值啊
String type = StringUtil.trim(map.get("pushType"));
request.setAttribute("type", type);
之後就可以取到了。