I want to load html , js, css files from file system while running tomcat 7. Tried the following approach, and none of it works.
1) put <Context docBase="D:\temp\uploads\myfile" path="/MySharedHTML"/> under conf/server.xml
2) created folder conf\Catalina\localhost and put ROOT.xml under it with following content
<?xml version='1.0' encoding='utf-8'?>
<Context docBase="D:\temp\uploads\myfile" path="/MySharedHTML"/>
when i tried to test my code with the following jsp file with tomcat running, nothing showed up
Bear Bibeault wrote:Of course it should, that's the whole point of the docbase. By defining the context, you create the ability to serve files from that context. I assume you have a WEB-INF at that location?
No i do not, it is just simple file or images or js files
You should not put Context elements in server.xml. That practice has been discouraged since at least Tomcat version 4 and Tomcat 9 will be the point release shortly.
The recommended place to put Context elements is under TOMCAT_HOME/conf/Catalina/localhost (assuming standard configuration). However, note that if you do that, the "path=" attribute will be ignored by Tomcat and the actual path will be the name of the context XML file (minus its ".xml" extension).
I personally recommend using forward-slash syntax for all filenames referenced in Java (D:/temp/uploads/myfile). It makes stuff more OS-portable and spares you possible pain from the dreaded "backslash-is-escape" errors.
Since about Tomcat 7, a WEB-INF/web.xml file is no longer mandatory, but nonetheless, you cannot simply dump files and directories anywhere you like in any structure you like and have Tomcat serve them up. Tomcat is a web server, not a file server. Anything that you want Tomcat to serve to a web client (such as a browser) must be contained in a WAR and properly deployed to Tomcat.
"privilege" comes from the Latin words for "private" and "law" (legal) and dates to feudal times. To "claim privilege" meant that you were above the laws that applied to the common people.
All that thinking. Doesn't it hurt? What do you think about this tiny ad?