我遇到一个jsp问题,我要做加入购物车,页面上显示的是session中的值(某个货物的信息),有个输入框,输入货物数量,然后把货物的id和数量都返回给servlet,一个值从输入框获得,一个使用的EL语言输出的session值,我不知道该怎么传,使用多种方法都只能传递一个。我用url传值和表单只能传id,用jquery的post()方法只能传数量,有点蒙,不知道该怎么做,特此求助。代码就写的很乱,请多包涵。
<table width="100%" border="0" cellpadding="9" cellspacing="9">
<c:forEach items="${requestScope.lists}" var="bridge">
<tr>
<td align="left"><img src="/${bridge.goods.goods_pic}" width="520" height="240" style="border:1px solid #ccc; padding:3px;"/></td>
</tr>
<tr>
<td align="left">菜品名称:${bridge.goods.goods_name}</td>
</tr>
<tr>
<td align="left">菜品介绍:${bridge.goods.goods_miaoshu}</td>
</tr>
<tr>
<td align="left">菜品价格:${bridge.goods.goods_shichangjia}</td>
</tr>
</c:forEach>
<tr>
<td align="left">预订数量:<input type="text" name="quantity" value="1" size="8" onkeyup="this.value=this.value.replace(/\D/g,'')" /></td>
</tr>
<tr>
<td><!-- <button type="button" class="btn btn-primary" onclick="ee1()">加入购物车</button> -->
<a href="AddToCart?goods_id=<c:out value="${bridge.goods.goods_id}"></c:out>&quantity=我不知道怎么写"><button type="button" class="btn btn-primary">进入购物车(必点)</button></a></td>
</tr>
</table>
</div>
<script type="text/javascript">
function ee1(){
var quantity1=$("#quantity").val();
$.post("AddToCart",
{
quantity:quantity1,
},
function(data,status){
if(data=="success"){
alert("success");
}
else{
alert("ss");
},"text")
}
</script>
<table width="100%" border="0" cellpadding="9" cellspacing="9">
<c:forEach items="${requestScope.lists}" var="bridge">
<tr>
<td align="left"><img src="/${bridge.goods.goods_pic}" width="520" height="240" style="border:1px solid #ccc; padding:3px;"/></td>
</tr>
<tr>
<td align="left">菜品名称:${bridge.goods.goods_name}</td>
</tr>
<tr>
<td align="left">菜品介绍:${bridge.goods.goods_miaoshu}</td>
</tr>
<tr>
<td align="left">菜品价格:${bridge.goods.goods_shichangjia}</td>
</tr>
</c:forEach>
<tr>
<td align="left">预订数量:<input type="text" name="quantity" value="1" size="8" onkeyup="this.value=this.value.replace(/\D/g,'')" /></td>
</tr>
<tr>
<td><!-- <button type="button" class="btn btn-primary" onclick="ee1()">加入购物车</button> -->
<a href="AddToCart?goods_id=<c:out value="${bridge.goods.goods_id}"></c:out>&quantity=我不知道怎么写"><button type="button" class="btn btn-primary">进入购物车(必点)</button></a></td>
</tr>
</table>
</div>
<script type="text/javascript">
function ee1(){
var quantity1=$("#quantity").val();
$.post("AddToCart",
{
quantity:quantity1,
},
function(data,status){
if(data=="success"){
alert("success");
}
else{
alert("ss");
},"text")
}
</script>
{
quantity:quantity1,
//这里直接写货物ID就可以了啊,为啥不可以传?
// id:id
},
第一次<input type="hidden" id="goodid" value="<c:out value="${bridge.goods.goods_id}"></c:out>"/>
fuction ee1(){
var quantity1=$("#quantity").val();
var goodid=$("#goodid").val();
$.post("AddToCart",
{
quantity:quantity1,
goodId:goodid,
},function(data,status){
if(data=="success"){
alert("success");
}
else{
alert("failure");
},"text")
}但是报错java.lang.NumberFormatException:null
at java.lang.Integer.parseInt(Unknown Sourse)
就是Servlet中的Integer goodId=Integer.parseInt(request.getParameter("goodId"));
Servlet中得到了quantity,没得到goodId。后来我直接在js中写var goodid="${bridge.goods.goods_id}";
还是不行
为什么还要写out..
<input type="hidden" id="goodid" value="${bridge.goods.goods_id}"/>
直接这样不就好了吗0.0 .. 你在界面输出goodid看看有没有拿到值,感觉可能是这里的问题