开发者

JSF Image and absolute path [duplicate]

This question already has answers here: Load images from outside of webapps / webcontext / deploy folder using <h:graphicImage> or <img> tag (4 answers) Closed 8 years ago.

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 6

EDIT

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)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜