I have a servlet running under Tomcat. I need to serve some files, I guess we can call them semi-static (which change occasionally ... they are updated by another part of the app) from an external (to the WEB-APP) directory. I have managed to do this by adding the following to my context.xml in the META-INF directory
<Context aliases="/working_dir=c:/apache_tomcat_working_dir" ></Context>
This works fine, in my HTML I refer to the file as
<img src="/myWebbApp/working_dir/fixpermin_zoom.png">
and in my web.xml inside WEB-INF I let the default server handle png files as follows
<!-- use default for static serving of png's, js and css, also ico -->
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
So this works fine. But I want to set the external directory from inside java code, not by editing the context.xml file.
Now in the init()
method of the servlet I can get the ServletContext.
ServletContext sc = getServletContext();
If I examine this variable sc
in the debugger, I can see the alias string several levels deep, see the attached image. How can I get at this alias string programatically?
I have checked the ServletContext docs, but i can't find it very helpful.
Any help much appreciated.
(source: choicecomp.com)