0
這裏是servlet部分:如何在轉發之後在JSP上打印?
Gson gson = new GsonBuilder().setPrettyPrinting().create();
session.getAttribute("XMLData");
String jsonArray = gson.toJson(xmlFromDB);
RequestDispatcher reqDis = request.getRequestDispatcher("/index.jsp");
reqDis.forward(request, response);
response.getWriter().print(jsonArray);
JSP:
<body>
<div align="center">
<table id="list">
<tr>
<td />
</tr>
</table>
</div>
<div id="pager"></div>
</body>
js文件:
jQuery(document).ready(function() {
$("#list").jqGrid({
url : "GridServlet",
datatype : "json",
mtype : 'POST',
...
});
但是當我轉發到index.jsp
,則顯示空白JQ電網,而不是json數組,我正在打印。
您是否在轉發之前嘗試寫入響應? –