How to retrieve the file in JSON format in JSP? [duplicate]
I want to ask a question about the JSON and JSP. I have 2 JSP (JSP1 & JSP2) pages and 1 JSON format f开发者_JAVA百科ile.
Both of the JSP pages are pack into a .war file. The JSON file is stored in a web server(e.g. http://examp;e.com
). And I have to do the following tasks:
1) Open the JSP1 (has a link)
2) When the user clicks the link, it will call the JSON file (http://examp;e.com
)
3) Display the JSP2 and show the content of the JSON file
{ "class":
{
"number": 2,
"student":
{
"name": "Tom",
"age": 1
},
"student":
{
"name": "May",
"age": 2
}
}
}
I have the basic knowledge of the HTML and the JSP, but I don't know how to do this action. Should I use the in the JSP1, if yes, what object should I use in order to retrieve the JSON content? thank you very much.
if it's only about displaying the JSON content available at some remote location into your page, you can probably use a hidden iframe linked to the location. keep the iframe invisible initially, and when the user clicks it, display it. you can use the "display" style property to toggle the visibility of the frame.
but remember, for this to work, the JSON text should be available as a plain text/html file. in other words, if the JSON object is present within the script tags, then you'll have to adopt a different approach.
精彩评论