【发布时间】:2013-10-26 05:51:15
【问题描述】:
我正在编写一个 servlet,它将接受来自 AJAX 请求的 POST 数据。
这是我从客户端发送的代码:
$.ajax({
type: "POST",
url: "urlservlet",
data: "{type:'" + "country" +
"', country:'" + $('#country').val() +
"'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(response) {
}
这是 servlet 代码:
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
string test = request.getParameter("type");
}
但问题是我总是得到等于 null 的类型。我不知道为什么。
请帮助我。
【问题讨论】:
-
你的标题是
getP(data),而你的代码是getP(type)。真正的问题是什么?