Search code examples
javaservletsjakarta-eeconfiguration-filesreadfile

How can Java Web read new changes on attributes automatically?


I just have created a Java Filter that, if one of its properties has a true value, the filter will redirect all the requests to a maintenance JSP (the server is not operational). If that property has a false value, the filter will redirect to the right target. The filter reads the boolean value from a config.properties file. It's something like this:

// Read the file property
private static boolean MAINTENANCE = Boolean.parseBoolean(p.getProperty("maintenance"));
...

if(MAINTENANCE) {
   redirectToURL("maintenance.jsp"); // maintenance JSP
}
else {
   chain.doFilter(request, response); // requested jsp/servlet
}
...

The point is... If my Web is running and I want to put it in maintenance mode, how could I do to make the server reads the new value of that property from the file?

I mean: I connect to the server, edit the config file, set "maintenance" property to value equal to true... But, how can I do to make the web application read it?

Thanks!


Solution

  • Thanks to @aribeiro, I achieved the solution for me.

    For the WebApp startup, I would read the properties from the file.

    When I want to make a change of some attribute, I would have to use a request that changes explicitly the value (maybe from an own admin panel).