The web deployment descriptor is loaded and parsed when the web container is first started. By default, changes to the descriptor are not detected and reloaded while the container is running. In fact, not many containers even provide this functionality—it’s typically not a wanted feature, due to the possible security issues involved. The Struts configuration files also are loaded and parsed when the container is launched, and changes to these configuration files also are not automatically detected; the same security issues are present.
Some applications might require the ability to reload the Struts
configuration files without restarting the web container. If your
application is one of them, there are ways you can do this. One
approach is to create a Struts action that will reinitialize the
ActionServlet
(you may want to restrict which
users can call this action). Once the
ActionServlet
is reinitialized, everything will be
new and the application can again service requests, just like before.
A second strategy is to create a thread that monitors the
lastModifiedTime
of the configuration file. It can
sleep for a few seconds and, upon awakening, compare the
lastModifiedTime
of the file against the one
stored in a variable. If they are different, the file has changed and
it’s time to reload the application. This approach
is nice because you don’t have to worry about an
unwelcome user reloading your application. However, the time that it
gets reloaded is entirely up to the thread.
Get Programming Jakarta Struts now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.