开发者

why would an application use an image servlet

I have seen some applications that开发者_JAVA百科 use a servlet to serve the images. What would be the purpose of this?


Could be because of following reasons

  1. URL processing required to fetch the image. e.x, fetching the image based on username
  2. The image is stored in database
  3. Some image processing is required like rotate, zoom etc


Possibly to impose user authenication in some way, ie: not all users have the rights to view all images


Dynamically generated images would be an example.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜