jsp标签取出传递参数注意

时间:2023-03-08 21:56:00
jsp标签<c:forEach>取出传递参数注意

运行书里的代码,其中servlet可以通过以下两个方式向jsp传参数:

1.         request.getSession().setAttribute("productList",productList);
            response.sendRedirect("displayAllProduct_3.jsp");
2.
             request.setAttribute("productList", productList);
             RequestDispatcher rd = request.getRequestDispatcher("/displayAllProduct_2.jsp");
             rd.forward(request, response);
然后,在jsp页面中用el表达式取出参数的
过程中忽略了:
  <c:forEach var="product" items="${requestScope.productList}"  varStatus="status">
  <c:forEach var="product" items="${sessionScope.productList}"  varStatus="status">
的区别
forEach语句中取出对象并用取名为  var XX  ,XX 是你要循环集合的别名,varStatus 是循环索引,
注意:通过requestScope.productList获取到参数,所以必须通过先访问servlet然后才有结果输出