今天下午寫了一個簡單的學生管理系統來練習java web相關的知識,但是在loginServlet裡面登入成功後,要把學生資訊查詢并且存儲到session中
if(flag){
//查詢所有的學生資訊
stusDao stus = new stusDaoImpl();
List<Student> list = stus.findAll();
//将學生資訊存儲到作用域中,目前我存儲到session中
request.getSession().setAttribute("list", list);
//重定向跳轉到指定頁面
response.sendRedirect("stu_list.jsp");
然後再另一個stu_list.jsp頁面中顯示
jsp頁面代碼如下(報錯的)
<c:forEach items="${sessionScope.list } " var="stu">
<tr align="center">
<td>${stu.id }</td>
<td>${stu.name }</td>
<td>${stu.gender }</td>
<td>${stu.age }</td>
<td>${stu.address }</td>
</tr>
</c:forEach>
報錯說javax.el.PropertyNotFoundException: Property [id] not found on type [java.lang.String]
也就是擷取不到list對象,是以找不到int........就是因為上面多了個空格(很弱智的錯誤!)
<c:forEach items="${sessionScope.list }" var="stu">
正确的應該是這個,在jstl的forEach裡,items裡面應該是EL表達式,而且不能有空格!!!!!!