I have seen some applications that use a servlet to serve the images. What would be the purpose of this?
Asked
Active
Viewed 230 times
4 Answers
3
Possibly to impose user authenication in some way, ie: not all users have the rights to view all images

Steve
- 1,769
- 2
- 22
- 33
3
Could be because of following reasons
- URL processing required to fetch the image. e.x, fetching the image based on username
- The image is stored in database
- Some image processing is required like rotate, zoom etc

Ramesh PVK
- 15,200
- 2
- 46
- 50
1
You can display images packed in your WAR using the path for the image relative to the context root of your application. But for images stored on your hdd (eg: C:\images\picture.jpg), how can you give that path if you can't pass the context root ? If you simply gave the path from your hdd you would get something like this: http://localhost:9080/your-app/C:/images/picture.jpg
So you need to load your image into a byte array on your servlet and then send the content of the picture using the ResponseWriter of the servlet.
It's the only way.

Cosmin Cosmin
- 1,526
- 1
- 16
- 34
-
There are more ways though. See also http://stackoverflow.com/questions/4543936/load-the-image-from-outside-of-webcontext-in-jsf/4543951#4543951. – BalusC Jun 04 '11 at 03:12
-
I see, but it's not standard .. it's a feature of some containers, I think ? – Cosmin Cosmin Jun 04 '11 at 10:51