1
我有一個創建JsonObject的servlet。在JSP中打印JSON對象
JsonObject jsonObject=new JsonObject();
jsonObject.addProperty("name", "john");
jsonObject.addProperty("name", "Smith");
jsonObject.addProperty("name", "Ram");
HttpSession session=request.getSession(true);
session.setAttribute("jsonObject", jsonObject);
RequestDispatcher rd = request.getRequestDispatcher("viewpage.jsp");
rd.forward(request, response);
這是我的JSP頁面
<%@page import="com.google.gson.JsonObject"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>View Json</title>
<%
JsonObject jsonObject=(JsonObject)session.getAttribute("jsonObject");
%>
</head>
<body>
<h6>JSON View</h6>
<br>
<%=jsonObject%>
</body>
</html>
但是當我運行這一點,JSP文件只打印最後數據。以下是輸出
JSON View
{"name":"Ram"}
如何打印整個?由於
@Shijuķ巴布沒有你理解這個問題 – PSR 2013-03-18 07:49:54
是。謝謝。但是,如果我想添加許多名稱作爲內部數組呢? – 2013-03-18 07:52:42