JSON 개체를 자바 스크립트에서 java 서버let으로 게시하고 싶습니다. 자바 코드 다음자바 서블릿 JSON 데이터 구문 분석
var a = {};
function SaveInfo(c)
{
document.getElementById("saveButton").className = "savebutton";
document.getElementById("cancelButton").className = "cancebutton";
var z= $(c).parent().parent().attr('id');
a[z] = c.value;
}
$("#saveButton").click(function(e){
if( document.getElementById("saveButton").className=="savebutton")
$.ajax({
url: "../../update",
type: 'POST',
dataType: 'json',
data: JSON.stringify(a),
contentType: 'application/json',
mimeType: 'application/json',
success: function (data) {
consol.log(data);
},
error:function(data,status,er) {
alert("error: "+data+" status: "+status+" er:"+er);
}
});
});
과 :
public void doPost(HttpServletRequest req, HttpServletResponse res){
JSONObject jObj;
jObj = new JSONObject(req.getParameter("mydata")); // this parses the json
Iterator it = jObj.keys();
while(it.hasNext())
{
String key = (String)it.next(); // get key
Object o = jObj.get(key); // get value
// store in session
}
}
JSON이 성공적으로 수신 나는 다음과 같은 자바 스크립트 코드를 사용했다. 나는 자바 스크립트를 통해 전달 된 두 값과 키를 읽을 수
jObj = new JSONObject(req.getParameter("mydata"));
: 문제에 대한 생성자가없는 것입니다.
감사합니다. – Shomit