简体   繁体   中英

Changes in conf/server.xml does not seem to have any effect during runtime

Here's what I know:

  • When uploading files given by users, we should put them in a folder outside the deployment folder. Let me call it D:\\uploads.
  • We should (somehow) add that folder (D:\\uploads) as a web app context.

Here's what I did:

  • I upload my files to the folder D:\\uploads.
  • I tried adding the web app context as it's mentionned here by adding the following row to TOMCAT_DIR/conf/server.xml:
    <Context docBase="D:\uploads" path="/uploads"/>

But that doesn't have any effect. When consulting http://localhost:8080/uploads/file.png or http://localhost:8080/uploads I get a HTTP Status 404 error.

So what I want to know:

  1. What did I do wrong ? How can I add my upload folder to Tomcat?
  2. Is there any better approach when it comes to uploading files ? Because I'm wondering what should I change if I want to deploy my application to another server where there's no D:\\uploads.

Change the docBase attribute. Use D:/uploads (with slash ) instead of D:\\uploads (with backslash ).

When dealing with files in Java, you can safely use / ( slash , not backslash ) on all platforms.


Regarding the differences you mentioned in the comments when starting the Tomcat from the IDE and from bin/startup.bat : It's very likely when you start the Tomcat from the IDE, it is not using the same context.xml your Tomcat is using. Just review the Tomcat settings in the IDE.


How to store uploaded files is a common topic at Stack Overflow. Just look around and you'll get surprised in how this topic is popular.

If you aren't happy enough in storing your files in D:/uploads or you'll have other servers accessing the files, you could consider storing them in some location in your network. Depending on your requirements, you can have one dedicated server to store your files or just share the folder which contains the files in your current server. The right decision will always depend on your requirements.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM