THIS IS A TEST INSTANCE. ALL YOUR CHANGES WILL BE LOST!!!!
...
No Format |
---|
Server server = ServerFactory.getServer(); //Note, this assumes the Container is "Catalina" Service service = server.findService("Catalina"); Engine engine = (Engine) service.getContainer(); Host host = (Host) engine.findChild(engine.getDefaultHost()); //Note, this assumes your context is "myContext" Context context = (Context) host.findChild("myContext"); Realm realm = context.getRealm(); |
Warning: The above recipe on how to obtain a Context
for a web application is a bit obsolete and does not work in Tomcat 7 and later (as Server is no longer a singleton). There are other ways to achieve that. An easy one is to add a Valve
or Listener
to a context, as those classes have access to Tomcat internals. There may be other ways mentioned in the archives of the users mailing list.
How do I redirect System.out and System.err to my web page?
...