Jsp scriptlet执行错误
以下代码:Jsp scriptlet执行错误,jsp,scriptlet,Jsp,Scriptlet,以下代码: <button type="button" id="button" onclick="<%cart.removeItem(0);%>">Click me</button> 点击我 假定在单击按钮时执行。但是, "<%cart.removeItem(0);%>" “” 在刷新页面而不单击按钮时执行。为什么会这样 干杯 这是完整的来源 <html> <head> <meta htt
<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>
JSP页面
点击我
我想你在这里把你的语言弄混了。我怀疑“cart”是一个Java对象,您只能在客户端修改JavaScript对象。你必须有这样的东西才能工作:
<script>
doRemoveFirst = function() { new Ajax.Request('removeFirst.page'); };
</script>
<button type="button" id="button" onclick="doRemoveFirst();">Click me</button>
感谢您的回复,Yes cart是一个javabean对象。您的代码“new Ajax.Request('removeFirst.page');”,删除第一页有什么意义?我已经编辑并输入了完整的源代码。希望能让你更好的理解我的代码。Thanks@user859385:您正在混合客户端和服务器端对象和操作。”“购物车”仅在服务器端可用,而“单击”按钮在客户端可用。我的Ajax.Request(它只是Ajax请求的原型库的简写)的要点是回调服务器,告诉它执行该页面。在该页面上,代码从cart对象中删除项0,然后重新呈现面向客户端的页面,注入更新的数据,或者使用Javascript隐藏/删除它。这更有意义吗?我明白你的意思。然而,即使我重新加载页面,我如何从javascript获得javabean对象属性呢。我研究了很多,除了javascriptbean之外,我找不到任何javascript和javabean协同工作的机制。但是javascriptbean太复杂了。@user859385:也许我的图片会帮助你更好地理解我的意思。
$(".item-row").first().remove();
$(".item-row").each(function(idx, el) {
var elem = $(el).children().find('.index-cell');
elem.text(+elem.text() - 1);
});