0

Here is my java Code

     Gson gson = new Gson();
     json = gson.toJson(applicationsList);
     System.out.println(json);

Here is my javascript file

       <html>
       <script>here i will use json data </script>
       </html

2 Answers 2

1

You need to use #renderHead() method of Component or Behavior. Read https://ci.apache.org/projects/wicket/guide/7.x/single.html#_adding_resources_to_page_header_section for more information.

public class MyComponent extends Component{

    @Override
    public void renderHead(IHeaderResponse response) {
       String json = ...;
       response.render(JavaScriptHeaderItem.forScript(json));
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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

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.