As someone who is relatively new to JSPs and their capabilities, I am currently working on developing a suite of 4 separate webapp dashboards, each with its own standalone URL and index.(jsp|html) pages. The backend of these dashboards, which is written in Java, can be built in various ways and deployed to different environments. Thankfully, there is a convenient .properties file located in WEB-INF/classes that contains system information such as build flavor and deployment environment - essential information that the UI requires.
Current Approach for Obtaining System Information for UI
In the shared UI Javascript, we are currently making a synchronous AJAX call on the main thread to a JSP, which reads the properties file and returns the information in JSON format to the caller (see code snippet below). I am looking to find a solution to eliminate this synchronous AJAX call and instead ensure that the required information is readily available to Javascript without the need for AJAX.
Question
How can I leverage JSPs and servlets to have this system information preloaded on the page for Javascript to access, without the need for an AJAX call? Additionally, how can I ensure that this solution is shared across all dashboards without duplicating JSP code in each index.jsp file?
For your reference, the current JSP code we are using is provided below. We fetch data from this JSP through an AJAX call and store it in global state variables for dashboard access.
<%@page language="java" contentType="application/json; charset=UTF-8" pageEncoding="UTF-8" %>
<%@page import="java.io.InputStream" %>
<%@page import="java.util.*" %>
<%@page import="com.google.gson.Gson" %>
<%
// Read properties file
Properties properties = new Properties();
properties.load(application.getResourceAsStream("/WEB-INF/classes/system.properties"));
Map<String, String> map = new HashMap<~>();
map.put("id", properties.getProperty("system.id", "unknown"));
map.put("type", properties.getProperty("system.type", "unknown"));
// Write JSON response
out.write(new Gson().toJson(map));
out.flush();
%>
Thank you in advance for your assistance as I navigate through this learning process!