【发布时间】:2017-02-19 02:07:12
【问题描述】:
我像这样从 servlet 发送一个 json
User profileUser = userService.get(id);
request.setAttribute("profileUser", profileUser);
JSONObject json = new JSONObject();
try {
json.put("profileUser", profileUser);
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
response.setContentType("application/json");
response.getWriter().write(json.toString());
在 ajax 调用中的 javascript
$.ajax({
cache : false,
type : "GET",
url : "UserServlet?id=" + userId,
success : function(result) {
alert(result.profileUser);
}
});
警报的结果是给我 Entity.user 但如果我想调用 result.profileUser.uuid 或该用户的属性返回我 undefined 。谁能帮帮我?
【问题讨论】:
-
实际的 HTTP 响应是什么?
-
@SLaks 302 临时移动
标签: java json ajax jsp servlets