jquery代码:
var username = $('#username').val();
var pwd = $('#pwd').val();
var param ='{"username":"'+username+'","pwd":"'+pwd+'"}';
$('#login').click(function(){
alert(param);
$.ajax({
type:'post',
url:'MyServlet',
data:param,
success:function(){}
})
})
servlet代码:
protected void doPost(HttpServletRequest request, HttpServletResponse resp)
throws ServletException, IOException {
String aa = request.getParameter("param");
System.out.println(aa);
}
这里获取不到ajax传过来的param的值 调试为空的 为什么 求大神帮忙
解决方案
data: {"orderId":orderId,"commant":commant},
或
data: "orderId=" + orderId + "&commant=" + commant
解决方案二:
可能你地址给错了吧 是不是webxml配错了
解决方案三:
参数param 的格式不对:servlet getParameter方法接受不了json对象,