hi folks, My application needs to store and view images on the fly. Where should I store the image and be able to get its http path in context? 1. storing in WebContent of the application. But i have a hard time getting its real path in the server's file system. Is this feasible? 2. storing in a global context(eg.the application_server_root), but the files stored on there can't be accessed by web client. Is there a place under application_server_root that is accessible by the web client? i am deeply confused. please help! thanks!
The most portable way would be to define a directory outside of your app. Configure it from either a context-init-param or a servlet-init-param and then write a servlet that streams the images from that directory.
This will work whether your app is being run as a packed war file or as an exploded file system.
If you know your app is always going to be run from an app server that can and will run it from an exploded file system (like Tomcat) then you can use ServletContext.getRealPath("/") to find the root of your webapp.
If you're planning on running in a clustered environment, you may want to consider storing the pics in a database or creating a separate and central image server.
You can check out SimpleStream at http://simple.souther.us for an example of streaming images from a servlet. This example, however, uses ServletContext.getResourceAsStream which is appropriate for resources stored within your webapp. To access a file outside of your webapp, you will need to get the input stream with a FileReader. This is a small change and should be pretty simple.
The most portable way would be to define a directory outside of your app. Configure it from either a context-init-param or a servlet-init-param and then write a servlet that streams the images from that directory. [/qoute] Is it possible to define a directory outside of my app and then access&create hyperlinks for the images from that directory without going through a servlet?
I checked out the simple StreamServlet, it's good for serving image files. I pass the servlet an image file name, then the image is served in a browser page. But if I want to imbedded the image in a page that has other text in it, can this be done? Of course it's easy if the images are stored under WebContent, but in my case they are possibly stored outside the WebContent, that's why I needed a Streaming servlet in the first place. Can this be done? How? I also checked out cewolf, it's good for imbedded charts filled with data, but not for imbedded images drawn from image files. Any idea? thanks!!!
A webpage with images is just a series of requests. Each image gets it's own request. The browser puts them all together. The index.html page in simpleStream is a perfect example. It has text (from the html page) and 3 images that were all streamed from the same servlet.