我想从servlet中获取对象。
我尝试在下面的代码,但我得到“对象对象”。我要“描述”的价值。
当我运行http://www.host.com/f/ServletToJSP1/时,我在浏览器中退出*
o/p {"Description":"Nutanix提供了破坏性的数据中心基础设施解决方案,这些解决方案具有高效率、大规模可伸缩性和简洁性。“}
控制台日志:未定义的ReferenceError: google未定义
我怎么能这么做?
jsp code
$.ajax({
url : 'ServletToJSP1',
type : 'GET',
dataType : 'json',
success : function(response) {
//response = $.parseJSON(response);
alert(response);
},
error : function(error) {
//error handling....
alert(error);
}
});servlet代码
JSONObject objTw = new JSONObject();
objTw.put("Description", "Nutanix provides disruptive datacenter infrastructure solutions that are hyper-efficient, massively scalable and elegantly simple.");
PrintWriter out = response.getWriter();
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
out.println(objTw);发布于 2013-09-10 08:32:45
访问响应对象的description属性。
$.ajax({
url : 'ServletToJSP1',
type : 'GET',
dataType : 'json',
success : function(response) {
//response = $.parseJSON(response);
alert(response.Description);
},
error : function(error) {
//error handling....
alert(error);
}
});发布于 2013-09-10 08:35:10
你在开发Chrome吗?您可以使用CTRL+SHIFT+I打开开发工具,然后打开控制台。
而不是警告(响应),尝试console.log(响应)对变量进行更深入的研究。
发布于 2013-09-10 08:37:36
试一试
success : function(response) {
alert(response[0].Description);
},在servlet代码中,尝试添加out.flush();
https://stackoverflow.com/questions/18714071
复制相似问题