Absolute Path of a Servlet Installation
I’m currently developing some Java Servlets and one of the tasks is to create images dynamically. But where to store them accessible for users?
If you want to show the user for example a graph of some stuff that changes frequently you need to generate the image dynamically. The rendering of the graphic is one thing, but where to store the picture so that the visitor can access it from the web?
There were many options to try, and I found that
getServletContext().getRealPath (".") from
ServletRequest › was the result I’ve been looking for. So to spare you the tests I’ll provide the different options (download):
Let’s assume your webapps-directory is
/var/lib/tomcat6/webapps/ , your servlet context is
project and the user asks for the servlet
test the output probably looks like:
That’s it for the moment ;-)
Leave a comment
There are multiple options to leave a comment: