Auranx
Auranx

Reputation: 51

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

Here's what I know:

Here's what I did:

    <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.

Upvotes: 1

Views: 405

Answers (1)

cassiomolin
cassiomolin

Reputation: 131137

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.

Upvotes: 1

Related Questions