这是我的java代码
Gson gson = new Gson();
json = gson.toJson(applicationsList);
System.out.println(json);
这是我的javscript文件
<html>
<script>here i will use json data </script>
</html
答案 0 :(得分:1)
您需要使用Component或Behavior的#renderHead()方法。请阅读https://ci.apache.org/projects/wicket/guide/7.x/single.html#_adding_resources_to_page_header_section以获取更多信息。
public class MyComponent extends Component{
@Override
public void renderHead(IHeaderResponse response) {
String json = ...;
response.render(JavaScriptHeaderItem.forScript(json));
}
}
答案 1 :(得分:0)
//We need to call a fetch function in the script tags fam
<script>
fetch('localhost:8080/getMyJson', (res, err) => {
err ? console.err(err) : console.log(res)
})
</script>
// the default HTTP method is set as GET