I have a system.properties
file with things like system version and build type that I'd like to show on my index.jsp pages (I have several in a suite of dashboards). What is the best way to provide those properties to my JSPs?
I'm currently reading the properties file directly from the JSPs, but that's cumbersome because it's several lines of code and it has to be duplicated across all of my JSPs. I did abstract that code out into its own JSP that I then include on my other JSPs, but that still feels cumbersome.
Ideally, I'd like to do the following from any page:
<body data-build-type='${buildType}' data-system-version='${systemVersion}'>
That could mean that I use a servlet or a servlet-filter, but I'm not sure.
Thanks!
You could use a WebListener that implements ServletContextListener.
So on deployment you could read the system properties and set them as attributes.
Either separately or in a map.
system.properties:
Lets say you have a file
system.properties
with content:WebListener:
The WebListener could be something like:
JSP:
In a JSP you can iterate through the
system
attribute like this:If the system properties are changing dynamically,
you can update them, directly in the context attribute (parallel to the system.properties file)