使用jstl標籤遍歷資料時,報javax.el.PropertyNotFoundException: Property [id] not found on type [java.lang.String
後臺報錯資訊:
javax.el.PropertyNotFoundException: Property [id] not found on type [java.lang.String] 2018-08-20 17:11:33.202 ERROR 5312 --- [nio-9010-exec-4] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [An exception occurred processing JSP page [/script/v_hr_employee_update.jsp] at line [102] 99: <div class="col-sm-6">
javax.el.PropertyNotFoundException: Property [id] not found on type [java.lang.String] |
報錯地方頁面程式碼:
<div class="form-group"> <label class="col-sm-3 control-label no-padding-right" for="form-field-1">職位</label> <div class="col-sm-6"> <select name="job.id" class="form-control"> <c:forEach items="jobs" var="job"> <option value="${job.id }">${job.name }</option> </c:forEach> </select> </div> </div> |
錯誤原因:使用c:forEach遍歷jobs資料時,items屬性取值應該寫成 items="${jobs }"