How can i use Tomcat to serve image files from a public folder outside webapps? I dont want to use a 2nd Apache fileserver on a different port since the image files are part of the same app. And i dont want to create a symlink to the public folder inside webapps since my app is deployed as a war file….Is there a simpler solution similar to using default servlet for static content inside webapps, for static content outside outside webapps
Share
You could have a redirect servlet. In you web.xml you’d have:
All your images would be in ‘/images’, which would be intercepted by the servlet. It would then read in the relevant file in whatever folder and serve it right back out. For example, say you have a gif in your images folder, c:\Server_Images\smilie.gif. In the web page would be
<img src='http:/example.com/app/images/smilie.gif'.... In the servlet,HttpServletRequest.getPathInfo()would yield ‘/smilie.gif’. Which the servlet would find in the folder.