一、post传送数据
加form标签,name必须相对应,传送多个数据较为方便,安全性相对较高,建议使用。
二、URL get传送数据
使用get方式传送数据,数据会显示在url,安全性低,密码禁止使用。
<a href="content?goodsid=${goods.goodsid} "></a>
ajax传送数据方式,使用在异步请求,不改变原有的也页面的情况下
jsp页面
//删除
$("input[value='删除']").click(function() {
$(this).parent().parent().remove();
sum1();
//遍历节点
doAjax($(this).parent().prev().val(), 0);
})
function doAjax(id, count) {
$.ajax({
type : "POST",
url : "changeCount",
data : {
id : id,
count : count
},
dataType : "json",
success : function(data) {
if(data=='false'){
alert("error")
}
}
})
}
controller页面
//**加@ResponseBody
@RequestMapping("changeCount")
@ResponseBody
public String changeCount(Integer id,int count,HttpSession session){
@SuppressWarnings("unchecked")
HashMap<Integer, Car> carMap = (HashMap<Integer, Car>) session.getAttribute("carMap");
Car temp = carMap.get(id);
if(count == 0){
carMap.remove(id);
}else{
temp.setCount(count);
carMap.put(id, temp);
}
session.setAttribute("carMap", carMap);
return "true";
}