本帖最后由 xingfeichen 于 2015-9-13 19:55 编辑
- <%@page import="com.xingfei.product.Product"%>
- <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
- <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
- <html>
- <head>
-
- <title>forEach遍历商品</title>
-
- </head>
-
- <body>
- <table border="1">
- <tr>
- <th>商品名称</th>
- <th>商品数量</th>
- <th>商品单价</th>
- <th>商品小计</th>
- </tr>
- <%
- ArrayList<Product> al = new ArrayList<Product>();
- al.add(new Product("计算机网络",100,20));
- al.add(new Product("java编程思想",200,80));
- al.add(new Product("javaWeb开发",20,60));
- request.setAttribute("products", al);
- %>
- <c:forEach begin="0" end="3" step="1" items="${products}" var="pts" varStatus="vs">
- <tr>
- <td>${pts.name}</td>
- <td>${pts.mount}</td>
- <td>${pts.price}</td>
- <td>¥${pts.price*pts.mount}</td>
- </tr>
-
- </c:forEach>
- <tr>
-
- <td colspan="3">总计</td>
- <td>${pts.price*pts.mount}</td>
- </tr>
- </table>
- </body>
- </html>
复制代码 怎么计算总价?
|
|