EL表达式相除问题
老师我现在做了一个购物车把之前的商品信息放进去并显示,但到要根据商品数量计算商品总价的时候总是不成功,想问一下老师,EL表达式可以和页面新输入的数字相乘并输出结果么
这是前台页面其中的一段代码
<div class="Shopping-cart-area pb-80">
<div class="container">
<div class="row">
<div class="col-12">
<form class="form-horizontal"
action="${pageContext.request.contextPath}/AddCartServlet"
enctype="multipart/form-data" onsubmit="return form()"
method="post">
<div class="table-content table-responsive">
<table class="table">
<thead>
<tr>
<th class="indecor-product-remove">remove</th>
<th class="indecor-product-thumbnail">images</th>
<th class="cart-product-name">Product</th>
<th class="indecor-product-price">Unit Price</th>
<th class="indecor-product-quantity">Quantity</th>
<th class="indecor-product-subtotal">Total</th>
</tr>
</thead>
<tbody>
<c:forEach items="${sessionScope.cartList }" var="cl"
>
<tr>
<td class="indecor-product-remove"><a
href="${pageContext.request.contextPath}/DeleteCartServlet?productId=${cl.productId}"><i
class="fa fa-times"></i></a></td>
<td class="indecor-product-thumbnail"><a href="#"><img
src="${cl.productPicture }" width="100px" height="100px"></a></td>
<td class="indecor-product-name"><a href="#">${cl.productName}</a></td>
<td class="indecor-product-price"><span class="amount">$${cl.productPrice}</span></td>
<td class="indecor-product-quantity"><input value="1" name="Cartquantity" id="Cartquantity" class="Cartquantity"
type="number">${cl.productAmount }</td>
<td class="product-subtotal" onsubmit="return money()"><span id="TotalPrice" class="TotalPrice">${cl.productPrice}*${cl.productAmount }</span></td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
<div class="row">
<div class="col-12">
<div class="coupon-all">
<div class="coupon">
<input id="coupon_code" class="input-text" name="coupon_code"
value="" placeholder="Coupon code" type="text"> <input
class="button" name="apply_coupon" value="Apply coupon"
type="submit">
</div>
<div class="coupon2">
<input class="button" name="update_cart" value="Update cart"
type="submit">
</div>
</div>
</div>
</div>
<div class="row">
<div class="col-md-5 ml-auto">
<div class="cart-page-total">
<h2>Cart totals</h2>
<ul>
<li>Total <span>$130.00</span></li>
</ul>
<a href="#">Proceed to checkout</a>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
下面是购物车类的代码
package com.imooc.domain;
public class Cart {
private String productId;
private String productName;
private String productPrice;
private String productPicture;
private String productDetail;
private int productAmount;
public Cart() {
super();
}
public Cart(String productId, String productName, String productPrice, String productPicture, String productDetail,
int productAmount) {
super();
this.productId = productId;
this.productName = productName;
this.productPrice = productPrice;
this.productPicture = productPicture;
this.productDetail = productDetail;
this.productAmount = productAmount;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public String getProductName() {
return productName;
}
public void setProductName(String productName) {
this.productName = productName;
}
public String getProductPrice() {
return productPrice;
}
public void setProductPrice(String productPrice) {
this.productPrice = productPrice;
}
public String getProductPicture() {
return productPicture;
}
public void setProductPicture(String productPicture) {
this.productPicture = productPicture;
}
public String getProductDetail() {
return productDetail;
}
public void setProductDetail(String productDetail) {
this.productDetail = productDetail;
}
public int getProductAmount() {
return productAmount;
}
public void setProductAmount(int productAmount) {
this.productAmount = productAmount;
}
@Override
public String toString() {
return "Cart [productId=" + productId + ", productName=" + productName + ", productPrice=" + productPrice
+ ", productPicture=" + productPicture + ", productDetail=" + productDetail + ", productAmount="
+ productAmount + "]";
}
}
正在回答 回答被采纳积分+1
老师我知道了,那现在我编写了一个代码想动态计算商品价格成衣其数量后的值,但param运行就没有生效,麻烦老师看看什么问题
<table class="myTable">
<thead>
<tr>
<th class="indecor-product-remove">remove</th>
<th class="indecor-product-thumbnail">images</th>
<th class="cart-product-name">Product</th>
<th class="indecor-product-price">Unit Price</th>
<th class="indecor-product-quantity">Quantity</th>
<th class="indecor-product-subtotal">Total</th>
</tr>
</thead>
<tbody>
<c:forEach items="${sessionScope.cartList }" var="cl"
>
<tr>
<td class="indecor-product-remove"><a
href="${pageContext.request.contextPath}/DeleteCartServlet?productId=${cl.productId}"><i
class="fa fa-times"></i></a></td>
<td class="indecor-product-thumbnail"><a href="#"><img
src="${cl.productPicture }" width="100px" height="100px"></a></td>
<td class="indecor-product-name"><a href="#">${cl.productName}</a></td>
<td class="indecor-product-price"><span class="amount">$${cl.productPrice}</span></td>
<td class="indecor-product-quantity"><input value="1" name="Cartquantity" id="Cartquantity" class="Cartquantity"
type="number"></td>
<td class="product-subtotal" onsubmit="return money()"><span id="TotalPrice" class="TotalPrice">${cl.productPrice*param.Cartquantity}</span></td>
</tr>
</c:forEach>
</tbody>
</table>
可以获得商品数量,但最后的计算值仍然为0,后台也没有报错
EL表达式相乘,不好意思老师打错了
- 参与学习 人
- 提交作业 676 份
- 解答问题 9666 个
本阶段将从前端网页搭建入手,到Java Web基础,前后端结合助你完成Java Web小白的蜕变!
了解课程
恭喜解决一个难题,获得1积分~
来为老师/同学的回答评分吧
0 星