This content has been marked as final. Show 2 replies
from the JavaDocs
java.lang.String getRealPath(java.lang.String path)
Gets the real path corresponding to the given virtual path.
For example, if path is equal to /index.html, this method will return the absolute file path on the server's filesystem to which a request of the form http://<host>:<port>/<contextPath>/index.html would be mapped, where <contextPath> corresponds to the context path of this ServletContext.
The real path returned will be in a form appropriate to the computer and operating system on which the servlet container is running, including the proper path separators.
Resources inside the /META-INF/resources directories of JAR files bundled in the application's /WEB-INF/lib directory must be considered only if the container has unpacked them from their containing JAR file, in which case the path to the unpacked location must be returned.
This method returns null if the servlet container is unable to translate the given virtual path to a real path.
path - the virtual path to be translated to a real path
the real path, or null if the translation cannot be performed
So instead of
String imageDirPath = servletCtx.getRealPath("");
wouldn't it mean you need to use
String imageDirPath = servletCtx.getRealPath("/");
Also keep in mind that if e.g. your development is on Windows and the production server is UNIX, path and case may be different
If the absolute/relative paths are obtained to get an image use the resource handling new feature in JSF 2.0.
Create a WebContent/resources/images directory and add the images to the images directory. In a JSF page an image (logo.jpg for example) may be used with
<h:graphicImage library="images" name="logo.jpg"></h:graphicImage>