Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9226937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T04:56:52+00:00 2026-06-18T04:56:52+00:00

I got this servlet which creates JSON data and I want to pass this

  • 0

I got this servlet which creates JSON data and I want to pass this data on to a jsp page which is supposed to display the data via the InfoVis toolkit.

servlet.java

JSONObject json = new JSONObject();
    JSONArray toplevel = new JSONArray();
    JSONObject sublevel;

    try{

        json.put("id", "node" + 0);
        json.put("name", "name" + 0);

        int count = 5;
        for(int i=1; i < count; i++){
            sublevel = new JSONObject();
            sublevel.put("id", "node" + i);
            sublevel.put("name", "name" + i);
            toplevel.put(sublevel);
        }
        json.put("children", toplevel);
    } catch (JSONException jse) {

    }

    request.setAttribute("jsonString", json.toString());
    RequestDispatcher dispatcher = request.getRequestDispatcher("graph.jsp");
    dispatcher.forward(request, response);

The following Code is provided by the InfoVis Toolkit and I’m not sure if it can be changed. Or at least I don’t have enough experience in JS to change it.

graph.jsp

<body onload="init('${jsonString}');">

spacetree.js

function init(jsonString){

    var json = jsonString;

Originally the function call is only

<body onload="init()">

but the init() function has the JSON variable hardcoded, which is of course not useful at all. So I’m looking for a way to make that dynamic. But since theres quotations inside the string it now totally messes up the onload=init() function call..

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T04:56:53+00:00Added an answer on June 18, 2026 at 4:56 am

    The cheap and easy way is to modify the JSP so it outputs this:

    <script>
    var theData = ${jsonString};
    </script>
    <body onload="init(theData);">
    

    The downside to that is that it creates a global variable, but if you’re calling init in that way, init is already a global, so that ship has sailed. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got a JSP page which contains a textbox, wrapped in a form. This
I got this servlet which return a pdf file to the client web browser.
I've got a JSP page with a piece of Javascript validation code which limits
Got this site with UN/PW set via the Createuserwizard control. Client considers PW too
I got this broken pipe exception which again lead to that my Spring application
In this image (which I got from here ), HTTP request sends something to
I've got a problem with the authentication features of Servlet 3.0: With this code
I got this error when I tried to access my development site via http://localhost/home/index.html
Right, here's my situation, I have a form on a page (index.jsp) which submits
I got hand-written security, simple servlet-filter which redirect not-authorized user to their login pages.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.