I want to put my images to db but i want to have a link on each image. So I have the idea to copy the image to the temp dir of tomcat (or weblogic). But I must map the tempdir to a virtual path.
How do it ?
I want to put my images to db but i want to have a link on each image. So I have the idea to copy the image to the temp dir of tomcat (or weblogic). But I must map the tempdir to a virtual path.
How do it ?
Just create a servlet and in its doGet
method serve a binary image content ( Content-Type: image/jpeg, or gif ).
Make sure to set the following fields in HttpServletResponse:
Then retrun the image binary as a body of HttpServletResponse, write it directly to a stream obtained through HttpServletResponse.getOutputStream
.
You can pass image ID to this servlet as a URL parameter, so you can serve different images through the same servlet. You may even cache images on disk, but because you have a servlet you will have an ability to setup a temp directory without virtual mapping.
EDIT
Actually you can create several virtual mappings to this servlet and in the servlet doGet
method examine context path and serve the image based on that context path name.