我想从json获取参数,所以我有一个代码:
@RenderMode(name = "VIEW")
public void serveResource(ResourceRequest resourceRequest, ResourceResponse resourceResponse) throws PortletException, IOException {
JSONObject jsonObject = JSONFactoryUtil.createJSONObject();
resourceRequest.setAttribute("resourceUrl", "http://localhost:8080/");
jsonObject.put("rowsPerPage", 10);
jsonObject.put("page", 1);
jsonObject.put("total", 100);
PrintWriter writer = resourceResponse.getWriter();
writer.write(jsonObject.toString());
}
应该用显示以下内容的 JavaScript 方法编写什么:rowsPerPage、page、total
我有一个 JavaScript 代码:
$.getJSON('http://localhost:8080/', function(jd) {
alert(jd.rowsPerPage);
});
JSP 页面:
<%@ taglib uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
This is the <portlet:resourceURL var="testURL" id="view.jsp" escapeXml="false" />
<br/><br/>
<div id="myGrid" style="width:600px;height:500px;"></div>
<div id="pager" style="width:600px;height:20px;"></div>
但这是错误的,为什么?