JSF Image and absolute path [duplicate]
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?
I know this give me the path to my project-war
ServletContext servletContext = (ServletContext) FacesContext.getCurrentInstance().getExternalContext().getContext();
String path = servletContext.getRealPath("");
Is there a way to ge开发者_Go百科t me to the web/application root?
Primefaces 2.2-RC2
Glassfish 3.0.1 Mojarra 2.0.3 Java EE 6EDIT
After a bit research, I learn the PrimeFaces allow you to stream the content of the image using FileInputStream
, and you can FileInputStream
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.
Here is the link I post to notify their developers about this major bugs. http://primefaces.prime.com.tr/forum/viewtopic.php?f=3&t=7052
Any other idea?
Just image a special servlet, ImageServlet
that is mapped to /image/*
(for example), and send the images from it (getting them as an InputStream
, and writing this to the response OutputStream
)
精彩评论