0

I have a jsp code, where I fetch some JSON data from JAVA Class file. [Basically openfire users]

Now I get the data successfully, but I want to show this data in HTML table format.

How do I Do this ?

My JSP Code :

<%@ 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"));

%>

And I get Response from the JAVA Class method like this :

[{"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}]

As I am very new to JAVA and JSP I don't know how to parse this data to HTML Table.

So Please help.

roeygol
  • 4,908
  • 9
  • 51
  • 88
Rajan
  • 2,427
  • 10
  • 51
  • 111
  • Use `JSONObject` to parse `JSON` data – Jyothi Babu Araja Dec 27 '16 at 08:28
  • Can u please put up a reference like @JyothiBabuAraja As i am new to JAVA and JSp – Rajan Dec 27 '16 at 08:58
  • Must divide problem: 1. parse JSON to variable (object, JSONObject is good) 2. Build HTML table with data. There is nothing like one-step parse – Jacek Cz Dec 27 '16 at 10:22
  • @JacekCz to use JSONObject do i need to add this to Java class file ? Or i can use directly in jsp pages ?? M being very dumb as i have a little knowledge with java and jsp – Rajan Dec 28 '16 at 05:38

2 Answers2

1

You can see here how to do it. You can populate it in Javasript or jQuery, but it is better to use JSTL and not just call java code inside JSPs.

Community
  • 1
  • 1
ddarellis
  • 3,912
  • 3
  • 25
  • 53
1

I would suggest you use mustache als template engine.

It allows you to use a HTML fragment as template (store it as resource) where double curly brackets (hence the name Mustache) denote the insertion points.

The full documentation of the Mustache syntax is here and a Java example here. Let us know how it is going.

stwissel
  • 20,110
  • 6
  • 54
  • 101