@RequestMapping("changeState")
public String changeState(HttpServletRequest req){
System.out.println(req.getParameter("status"));
String status = req.getParameter("status");
int id = Integer.parseInt(req.getParameter("id"));
Map<String, Object> map = new HashMap<String, Object>();
if("0".equals(status)){
map.put("status", "1");
map.put("id", id);
costDao.stateChange(map);
}else{
map.put("status", "0");
map.put("id", id);
costDao.stateChange(map);
}
return null;
}
Controller返回值如何填写??
以下是通过Ajax发送的同步请求
function startFee(status, id) {
var r = window.confirm("确定要启用此资费吗?资费启用后将不能修改和删除。");
if(r){
var xhr = getXhr();
xhr.open("get", "changeState.do?status="+status+"&id="+id, false);
xhr.onreadystatechange=function(){
if((xhr.readyState==4)&&(xhr.status==200)){
alert("4");
}
};
xhr.send();
}
document.getElementById("operate_result_info").style.display = "block";
}
解决办法:使用PrintWrite写一个返回值,并且该Controller声明为void