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 <img src>
when it encounters an <img>
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 <Context>
to the server.xml
<Context docBase="/path/to/images" path="/images" />
and in Glassfish it's a matter of adding an alternatedocroot
to the glassfish-web.xml
<property name="alternatedocroot_1" value="from=/images/* dir=/path/to" />
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:
<p:graphicImage value="/images/#{image.imageName}" />
Other ways involve using PrimeFaces StreamedContent
API or homegrowing a servlet.
See also:
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…