How to show the server path image to PrimeFaces p:graphicImage?

后端 未结 1 1880
栀梦
栀梦 2020-12-15 13:44

When I retreive server path and show into the p:graphicImage tag, then images are not displayed. Images are loaded into outside the webbapp folder. Server path

1条回答
  •  旧巷少年郎
    2020-12-15 14:27

    You're making a conceptual mistake. It's not the server who includes and sends the image along with the generated HTML output somehow. It's the webbrowser who downloads the image by its URL as specified in the when it encounters an tag in the HTML.

    So it has really to be a normal URL, exactly the one as the enduser would enter in the webbrowser's address bar, not a server specific local disk file system path. The enduser using the webbrowser really doesn't have that image on exactly that path on its local disk file system.

    Easiest would be to add the folder as a "virtual context" of the servletcontainer which you're using. It's unclear which one you're using. In Tomcat it's a matter of adding a new to the server.xml

    
    

    and in Glassfish it's a matter of adding an alternatedocroot to the glassfish-web.xml

    
    

    Refer the documentation of the servletcontainer for details. Ultimately they should be accessible by a normal URL so that you can just use for example:

    
    

    Other ways involve using PrimeFaces StreamedContent API or homegrowing a servlet.

    See also:

    • Simplest way to serve static data from outside the application server in a Java web application

    0 讨论(0)
提交回复
热议问题