Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

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

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 of the images are like this \qbsserverTest Folderestcar.jpg.

<p:graphicImage value="\qbsserverTest Folderest\#{image.imageName}" />

How can I make them to display? I am using PrimeFaces 3.0 and JSF 2.0 in Eclipse IDE.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...