我想从 servlet 获取对象。
我尝试下面的代码,但得到 "[object Object]" 。我想要“描述”值。
我在浏览器中运行http://www.host.com/f/ServletToJSP1/ *
o/p {“描述”:“Nutanix 提供颠覆性的数据中心基础架构解决方案,这些解决方案具有超高效率、可大规模扩展且非常简单。”}
在控制台日志中:Uncaught ReferenceError: google is not defined
我怎样才能做到这一点 ?
jsp code
$.ajax({
url : 'ServletToJSP1',
type : 'GET',
dataType : 'json',
success : function(response) {
//response = $.parseJSON(response);
alert(response);
},
error : function(error) {
//error handling....
alert(error);
}
});
小服务程序代码
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);