ajax 传值给servlet servlet收到的都是null 不知道为什么 请教大牛!
ajax://ajaxfunctionsave(){alert("hello");varrequest;if(window.XMLHttpRequest){request...
ajax:
// ajax
function save(){
alert("hello");
var request;
if(window.XMLHttpRequest){
request = new XMLHttpRequest();
}
else{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
//localhost:端口/项目各1�7/ManageServlet.do?名字=倄1�7
var url="/campusNavigation/ManageServlet.do";
var infor="buildingNum="+scene.objects.length+"&sendInfor="+sendInfor;
request.open("POST",url,true);
request.send(infor);
alert("sended!");
}
servlet:
public class ManageServlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String buildingNum = request.getParameter("buildingNum");
String sendInfor =request.getParameter("sendInfor");
String input= buildingNum+"@"+sendInfor;
System.out.println("-------------");
System.out.println(buildingNum);
System.out.println(sendInfor);
System.out.println(input);
System.out.println("-----------");
}
输出结果:
-------------
null
null
null@null
-----------
请教大牛! 展开
// ajax
function save(){
alert("hello");
var request;
if(window.XMLHttpRequest){
request = new XMLHttpRequest();
}
else{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
//localhost:端口/项目各1�7/ManageServlet.do?名字=倄1�7
var url="/campusNavigation/ManageServlet.do";
var infor="buildingNum="+scene.objects.length+"&sendInfor="+sendInfor;
request.open("POST",url,true);
request.send(infor);
alert("sended!");
}
servlet:
public class ManageServlet extends HttpServlet{
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String buildingNum = request.getParameter("buildingNum");
String sendInfor =request.getParameter("sendInfor");
String input= buildingNum+"@"+sendInfor;
System.out.println("-------------");
System.out.println(buildingNum);
System.out.println(sendInfor);
System.out.println(input);
System.out.println("-----------");
}
输出结果:
-------------
null
null
null@null
-----------
请教大牛! 展开
2个回答
展开全部
function save(){
alert("hello");
var request;
if(window.XMLHttpRequest){
request = new XMLHttpRequest();
}
else{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
//localhost:端口/项目各1�7/ManageServlet.do?名字=倄1�7
var url="/campusNavigation/ManageServlet.do";
var infor="buildingNum="+scene.objects.length+"&sendInfor="+sendInfor;
request.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
request.open("POST",url,true);
request.send(infor);
alert("sended!");
}
现在试试 可以不? 用post方式提交的时候需要加上 request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); get方式就不需要了
alert("hello");
var request;
if(window.XMLHttpRequest){
request = new XMLHttpRequest();
}
else{
request = new ActiveXObject("Microsoft.XMLHTTP");
}
//localhost:端口/项目各1�7/ManageServlet.do?名字=倄1�7
var url="/campusNavigation/ManageServlet.do";
var infor="buildingNum="+scene.objects.length+"&sendInfor="+sendInfor;
request.setRequestHeader("Content-Type",
"application/x-www-form-urlencoded");
request.open("POST",url,true);
request.send(infor);
alert("sended!");
}
现在试试 可以不? 用post方式提交的时候需要加上 request.setRequestHeader("Content-Type", "application/x-www-form-urlencoded"); get方式就不需要了
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询