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":"[email protected]","name":"Administrator","properties":null},{"username":"bizdd456d454mnc","email":"[email protected]","name":"bidzMNC","properties":null},{"username":"bizddd454mnc","email":"[email protected]","name":"bidzMNC","properties":null},{"username":"bizmnc","email":"[email protected]","name":"511515151515151","properties":{"property":[{"@key":"console.order","@value":"session-summary=1"},{"@key":"console.rows_per_page","@value":"user-summary=8"}]}},{"username":"dhaval","email":"[email protected]","name":"dhaval","properties":null},{"username":"keyur","email":"[email protected]","name":"keyur","properties":null},{"username":"minz","email":"[email protected]","name":"bidzMNC","properties":null},{"username":"patel","email":"[email protected]","name":"patelbhai","properties":{"property":[{"@key":"console.order","@value":"session-summary=1"},{"@key":"console.rows_per_page","@value":"user-summary=8"}]}},{"username":"rajan","email":"[email protected]","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.

4
  • Use JSONObject to parse JSON data Commented Dec 27, 2016 at 8:28
  • Can u please put up a reference like @JyothiBabuAraja As i am new to JAVA and JSp Commented Dec 27, 2016 at 8: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 Commented Dec 27, 2016 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 Commented Dec 28, 2016 at 5:38

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.