我很难找到为什么没有将我的setAttributes
传递到JSP中相应的EL标签中的原因。
servlet代码:
double total = 0;
double warning = 10000;
String path = getServletContext().getRealPath("/WEB-INF/homeitems.txt");
BufferedReader br = new BufferedReader(new FileReader(new File(path)));
String line;
while ((line = br.readLine()) != null) {
String[] parts = line.split(",");
double price = Double.parseDouble(parts[2]);
total = total + price;
}
br.close();
if (total > warning) {
request.setAttribute("total", total);
request.setAttribute("message", "WARNING: total value exceeds maximum value of $10,000");
getServletContext().getRequestDispatcher("/WEB-INF/admin.jsp").forward(request, response);
} else {
request.setAttribute("total", total);
getServletContext().getRequestDispatcher("/WEB-INF/admin.jsp").forward(request, response);
}
我尝试逐步使用NetBeans中的调试器,但是它显示了setAttributes
正在执行。
JSP页面:
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>A1 Home Inventory</title>
</head>
<body>
<h1>Home Inventory</h1>
<h3>Admin Summary</h3>
Total Value: $${total}
${message}
</body>
</html>
homeitems.txt文件内容:
living room,desk,200.0
living room,couch,500.0
kitchen,knives,100.0
bathroom,tub,2000.0
garage,car,8000.0
这是我的JSP中的EL,应该在其中显示属性值-但是在加载页面时,没有为请求属性total
或message
填充任何内容。
任何帮助将不胜感激:)