xmlhttp用post发送请求,但是servlet接收到的request里面,获取不到参数0
mfji01042013.06.08浏览897次分享举报
var http;
function test(element){
var trid=element.id;
var trvalue=element.value;
if(window.ActiveXObject){
try {
alert("ie");
http= new ActiveXObject("Msxml2.XMLHTTP") ;
} catch (e) {
try {
alert("ie2");
http= new ActiveXObject("Microsoft.XMLHTTP") ;
} catch (e2) {
;
}
}
} else if(window.XMLHttpRequest){
http= new XMLHttpRequest() ;
}
var url = "${it.rootUrl}controller/post";
var str="id="+trid+"&name="+trvalue;
http.onreadystatechange = callback;
http.open("POST",url,true);
http.setRequestHeader("Content-length",str.length);
http.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
http.send(str);
}
public void doPost(StaplerRequest req, StaplerResponse rsp)
throws ServletException, IOException, InterruptedException {
String result=null;
int count = Hudson.getInstance().getComputers().length;
// int c = 1;
String url = Hudson.getInstance().getRootUrl();
String[][] slave = getipmac();
// String temp=null;
System.out.println( "------------header---"+req.getHeader("id"));
System.out.println( req.getDateHeader("id"));
int c= Integer.parseInt(req.getParameter("id"));
String temp=req.getParameter("name");
System.out.println("---------------temp---"+temp);
System.out.println("------c-----"+c);
......
rsp.setContentType("text/html;charset=utf-8");
PrintWriter out=rsp.getWriter();
out.write(result); //将信息写入response
out.flush();
out.close();
// rsp.forwardToPreviousPage(req);
}
}
错误信息在 int c= Integer.parseInt(req.getParameter("id"));
没有获取到参数
应该如何传参数?