passing json data from servlet to jsp to js file

前端 未结 2 1768
臣服心动
臣服心动 2021-02-10 09:16

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

2条回答
  •  既然无缘
    2021-02-10 09:29

    You don't have to drop the JSON as a string - it's valid JavaScript syntax:

    
    

    When that's rendered by JSP, the end result — the HTML sent to the browser — will be something like:

    
    

    Now the only thing you may want to do is HTML encode the JSON, since you're dropping it as an HTML attribute value:

    
    

    Then your "init" function can expect a ready-to-use JavaScript object, with no need to call a JSON parser at all.

提交回复
热议问题