Whether or not you want to save the image binary in database or save the image file in server directory depends on your need.
The never ending debate is still going on and you can find it easily with several key strokes.
Here is how I do it(second approach) and it never disappoints me:
Assuming you are building an e-commerce website and want to host seller uploaded images such as product images and show them later.
- Save the uploaded image files physically on your server outside of your war .Let's say the directory is /baseFolder/ and the full path of the file is /baseFolder/path/to/image.jpg.
- Add a virtual host in Tomcat so that your http://localhost:8080/imageBase/ is pointing to the physical directory /baseFolder/. There are many other ways to make this kinds of mappings.
- Store the relative path /path/to/image.jpg in your database. So that when you want to show it you can simply say:
<img src="#{webappRoot}/baseFolder/#{pathRetrievedFromDatabase}"/>
. In this case it would be <img src="#{webappRoot}/baseFolder/path/to/image.jpg"/>
There are of course a lot of different ways to achieve the same thing.
This is the simplest way I can think of to explain how it is managed.
Hope it helps.