如何从JAVA方法打印JSON响应到HTML表?

时间:2016-12-27 08:25:37

标签: java html json jsp

我有一个jsp代码,我从JAVA Class文件中获取一些JSON数据。 [基本上是openfire用户]

现在我成功获取了数据,但我希望以HTML表格格式显示这些数据。

我该怎么做?

我的JSP代码:

<%@ page language="java" import="prov.*, java.util.*, java.io.*,java.text.*" contentType="text/html"%>
<%@ page errorPage="error.jsp" %>
<%

Openfire tc = new Openfire();

tc.getUsers("192.168.50.218","epvFjHq5RHA614C7");

out.println("Data Is As Below : " + tc.getUsers("192.168.50.218","epvFjHq5RHA614C7"));

%>

我从JAVA Class方法得到响应:

[{"username":"abcd","name":"","properties":null},{"username":"admin","email":"admin@example.com","name":"Administrator","properties":null},{"username":"bizdd456d454mnc","email":"bizMNC@bizrtc.com","name":"bidzMNC","properties":null},{"username":"bizddd454mnc","email":"bizMNC@bizrtc.com","name":"bidzMNC","properties":null},{"username":"bizmnc","email":"admin@example.com","name":"511515151515151","properties":{"property":[{"@key":"console.order","@value":"session-summary=1"},{"@key":"console.rows_per_page","@value":"user-summary=8"}]}},{"username":"dhaval","email":"dhaval@bizrtc.com","name":"dhaval","properties":null},{"username":"keyur","email":"keyur@bizrtc.com","name":"keyur","properties":null},{"username":"minz","email":"bizMNC@bizrtc.com","name":"bidzMNC","properties":null},{"username":"patel","email":"rau@example.com","name":"patelbhai","properties":{"property":[{"@key":"console.order","@value":"session-summary=1"},{"@key":"console.rows_per_page","@value":"user-summary=8"}]}},{"username":"rajan","email":"rajan@bizrtc.com","name":"rajan","properties":null},{"username":"+username+","email":"+email+","name":"+name+","properties":null}]

由于我是JAVA和JSP的新手,我不知道如何将这些数据解析为HTML表。

所以请帮忙。

2 个答案:

答案 0 :(得分:1)

您可以看到here如何操作。您可以在Javasript或jQuery中填充它,但最好使用JSTL而不只是在JSP中调用java代码。

答案 1 :(得分:1)

我建议您使用mustache als模板引擎。

它允许您使用HTML片段作为模板(将其存储为资源),其中双花括号(因此名称为Mustache)表示插入点。

Mustache语法is hereJava example here的完整文档。让我们知道它是怎么回事。