title: JSF Image and absolute path
body: <p>I know that for JSF to display an image, the path have to be from the web/application server root, not the system root. So no absolute path. But here is my problem. Since I will allow the user to upload their own pictures and later display them, I need to save the images somewhere. However, if I save the image inside my project, the future project redeploy might erase my pictures. As a result I think, it is best to upload to a folder that is not effected by future redeploy. But then h:graphicImage or p:graphicImage would not allow me to use absolute path. What are my options to solve this problem?</p>
  
  <p>I know this give me the path to my project-war</p>
  
  <pre><code>ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();  
  String path = servletContext.getRealPath("");
  </code></pre>
  
  <p><strong>Is there a way to get me to the web/application root?</strong></p>
  
  <p>Primefaces 2.2-RC2<br>
  Glassfish 3.0.1<br>
  Mojarra 2.0.3
  Java EE 6</p>
  
  <p><strong>EDIT</strong></p>
  
  <p><strong>After a bit research, I learn the PrimeFaces allow you to stream the content of the image using <code>FileInputStream</code>, and you can <code>FileInputStream</code> using absolute path. This can be a good solution, until, I tested and find out that this can only work on RequestScoped and SessionScoped Bean, but not ViewScoped.</strong></p>
  
  <p>Here is the link I post to notify their developers about this major bugs. 
  <a href="http://primefaces.prime.com.tr/forum/viewtopic.php?f=3&amp;t=7052" rel="nofollow">http://primefaces.prime.com.tr/forum/viewtopic.php?f=3&amp;t=7052</a></p>
  
  <p>Any other idea?</p>