我只是简单地想从我的服务器返回一个JSON对象(使用ajax)到客户端 - 所以我'米能够在客户端读取数据如何从我的休息服务发送json对象,以便我可以解析出客户端javascript
@GET
@Produces("application/json")
@Consumes("application/json")
@Path("/getStatus/")
public void getStatus(
@Context HttpServletRequest request,
@Context HttpServletResponse response) throws ServletException,
IOException
{
//create the JSON Object to pass to the client
JSONObject object=new JSONObject();
response.setContentType("text/javascript");
try
{
object.put("name", nameDataFromClass);
object.put("status",someData);
}
catch(Exception e)
{
throw new ServletException("JSON Hosed up");
}
String json = object.toString();
response.getOutputStream().println(json);
}
这将是在JSP客户端我想提取出来的数据
<html>
<head>
<!-- Calls in jQuery file -->
<script src="jquery.js"></script>
<title>JQuery Test</title>
<script>
$.getJSON("http://localhost:8080/scout/rest/admin/mamba/getStatus",
function(json)
{
alert("Server naame: " + json.name);
});
</script>
</head>
<body>
</body>
</html>
等什么不会:
然后从你的RESTful Web服务返回这个对象为你工作? – mkro 2011-06-16 20:25:24
客户端没有收到数据。我的宁静的java应该有回报吗?是否有一些我缺少的jquerry/ajax作品? – stackoverflow 2011-06-16 20:27:00
请求实际到达java层吗? – mkro 2011-06-16 20:28:00