Sending a JSON file to template when opening the page


I have a php/javscript page that creates a searchable list of users from a database.

Currently I host the page on the same server as Confluence and include it on a page with the html-include macro.

I would like to create a plugin that does that all in confluence with java.

I finished the "Write a simple Confluence blueprint plugin " Tutorial.

So when the page is opened there should be a java function that connects to a database and sends a JSON to the page.

Is this possible and does someone have some ressources on how I would go about this specific part (Executing a java function on page open and making data available to the page)