0
我想通過AJAX將JSON對象發佈到servlet。但是,該對象在servlet中爲null。我無法弄清楚這段代碼有什麼問題。無法通過AJAX將JSON對象從Javascript發佈到Servlet
JAVASCRIPT
function submitValues(event, val1, val2)
{
var xmlHttpObj = new XMLHttpRequest();
if(window.XMLHttpRequest)
{
xmlHttpObj = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
xmlHttpObj = new ActiveXObject("Microsoft.XMLHttp");
}
var jsonObject = submitTheValues(event, val1, val2);
alert("json is:" +jsonObject);
var json = JSON.stringify(jsonObject);
alert("json after stringify:" +json);
xmlHttpObj.open("POST", "../myapp/myservlet", true);
xmlHttpObj.setRequestHeader("Content-type", "application/json");
xmlHttpObj.send(json);
}
SERVLET
String jsonObj = request.getParameter("json");
非常感謝。我一直在努力爭取這一點。它工作得很好。 – Raghu 2013-03-12 19:09:32