How do I add aliases to a Servlet Context in java?
|
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
This works fine, in my HTML I refer to the file as
and in my web.xml inside WEB-INF I let the default server handle png files as follows
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
If I examine this variable
|
|||
feedback
|
As you can see in your debugger, your context is Tomcat's Context Object You can try following steps in Tomcat 6 and below:
Now you can add Host alias using
Here is the code snippet for Tomcat 7:
If there is no host in the mapper, please try below:
Hope this helps! |
|||||||||
feedback
|
I found another method
Please find my debugger screenshots below: Before the code snippet execution: After the code snippet execution: Hope this is more helpful. |
|||||
feedback
|