I upload images to a folder on the server's hard drive. Next I would like to display them back to the user. My question is; is it possible to map a system folder to a context relative path? And how to it? Entry in web.xml perhaps? ie. from "C:\img\" to "/resources/image/" (Of course, I could open the files in Java and stream myself but why do that when the container can do it?)
Alternatively, would you recommend storing images in a database and stream from there instead.
Thank you for taking time to answer a really basic question, my regards.
Absolutely do NOT upload anything to your WAR directories! It's not guaranteed to work in all environments and even where it does, the first time you update the WAR all your uploaded files will get nuked. Always upload to an external directory outside of the webapp server environment. Preferably one whose path can be configured via a deployment context definition and not hard-coded into the application. Or, like you said, upload to a database or something.
A web server is not a file server. So you will need a simple servlet to copy files from your image repository back out to the remote client. I'm afraid there's no standard copy-file servlet, but it's a simple matter to create one.
As to whether it's better to keep images in files or as BLOBs in databases, you can hear plenty of argument over that one. Files have the advantage of being easier to access. However, if you have database records referencing the files, keeping everything in one place reduces problems where the 2 repositories get out of sync.
An IDE is no substitute for an Intelligent Developer.