以下代码:
<button type="button" id="button" onclick="<%cart.removeItem(0);%>">Click me</button>
假设在单击按钮时执行。然而,
"<%cart.removeItem(0);%>"
当页面刷新而不单击按钮时正在执行。为什么会这样?
干杯。
这是完整的来源。
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<jsp:useBean id="cart" scope="session" class="myBeans.cart" />
<%
cart.addItem("aji", "1000", "1");
cart.addItem("ewer", "200", "1");
cart.addItem("dfwerweji", "10", "1");
cart.addItem("ldsjioi", "1320", "1");
String[] prodNames = cart.getProdNames();
double[] prices = cart.getProdPrices();
int[] qtys = cart.getProdQtys();
double total = 0;
for(int i=0; i<prodNames.length; i++){
total += prices[i]*qtys[i];
out.println(prodNames[i]);
out.println(" " + prices[i] + " ");
out.println("<input type=text name=newQty value=" + qtys[i] + ">");
out.println(" " + prices[i] * qtys[i]);
}
%>
<br/>
<button type="button" id="button" onclick="<%cart.removeItem(0);%>">Click me</button>
</body>
</html>