0
這裏是我的Servlet,其中將文本框值添加到ArrayList。我也在使用JavaBeans。在迭代JSTL中的ArrayList時獲取空白頁面
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
String companyName = request.getParameter("txtCompany");
double price = Double.parseDouble(request.getParameter("txtPrice"));
HttpSession session = request.getSession();
// Invoice r = new Invoice();
ArrayList<Invoice> list = (ArrayList<Invoice>) session
.getAttribute("EInvoice.list");
if (list == null) {
list = new ArrayList<Invoice>();
}
list.add(new Invoice(companyName, price));
session.setAttribute("EInvoice.list", list);
String url = "/Show.jsp";
RequestDispatcher rd = getServletContext().getRequestDispatcher(url);
rd.forward(request, response);
}
這裏是Show.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Show</title>
</head>
<body>
<c:forEach var="list" items="${EInvoice.list}">
<h1>${list.companyName} ${list.price}</h1>
</c:forEach>
</body>
</html>
我希望它顯示輸入的文本框的值,但所有我得到的是一個空白頁。任何想法爲什麼?當我正在學習JSTL時,請諒解任何愚蠢的代碼錯誤。