1. 程式人生 > >Servlet轉發到JSP,JSP取出值輸出不顯示問題

Servlet轉發到JSP,JSP取出值輸出不顯示問題

Servlet程式碼

//DAO取資料

List<Dishes> list = sDao.findAllDishes();

//將其放到request的域中

request.setAttribute("dishesList", list);

JSP程式碼

        <%
request.setCharacterEncoding("utf-8");
List<Dishes> list = (List<Dishes>) request.getAttribute("dishesList");

%>

//這裡的list控制檯列印有值

//但是JTSL輸出不了

        <div>
<c:forEach  var="Dishes" items="${pageScope.list}">
<div>${Dishes.dishesName}</div>
</c:forEach>

</div>

DBUG

//包導了//沒寫錯

so google

//在jsp的<%%>中將LIST存入Page域

//取出 成了

items="${cg}" 你把cg放到某個scope下。再在scope中讀出來。比如:pageContext.setAttribute("liset",liset);

ody>
<%
request.setCharacterEncoding("utf-8");
List<Dishes> list = (List<Dishes>) request.getAttribute("dishesList");
pageContext.setAttribute("list",list);

%>
<div>
<c:forEach  var="Dishes" items="${pageScope.list}">
<div>${Dishes.dishesName}</div>
</c:forEach>
</div>

//mark