Java 如何在xhtml页面中显示图像?

Java 如何在xhtml页面中显示图像?,java,maven,Java,Maven,我有一个Maven项目。我可以在我的数据库中上传图片,但我想把这个图片放到我的xhtml页面中 我的Java代码 private StreamedContent secilenMusteriResimi; public StreamedContent getSecilenMusteriResimi() { return secilenMusteriResimi; } public void setSecilenMusteriResimi(Streame

我有一个Maven项目。我可以在我的数据库中上传图片,但我想把这个图片放到我的xhtml页面中

我的Java代码

private StreamedContent secilenMusteriResimi;

public StreamedContent getSecilenMusteriResimi()
    {
        return secilenMusteriResimi;
    }

    public void setSecilenMusteriResimi(StreamedContent secilenMusteriResimi)
    {
        this.secilenMusteriResimi = secilenMusteriResimi;
    }

public void showImage()
{

    RequestContext.getCurrentInstance().update("panel");
    imagesPath = selectedImages.getPath();
    try

    {

        InputStream inputStream = new ByteArrayInputStream(selectedImages.getProfilresmi());
        BufferedImage resimData = ImageIO.read(inputStream);
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        ImageIO.write(resimData, "jpg", os);
        secilenMusteriResimi = new DefaultStreamedContent(new ByteArrayInputStream(os.toByteArray()), "image/jpg");

        //  secilenMusteriResimi = new DefaultStreamedContent(inputStream);

    }
    catch (Exception e)
    {
        e.printStackTrace();
    }

}
我的xhtml代码

<h:form>
            <p:dataTable id="table" var="img"
                value="#{musteriBean.musteriTanimlariListesi}"
                style="width: 500px;" selectionMode="single"
                selection="#{musteriBean.selectedImages}" rowKey="#{img.id}">
                <p:ajax event="rowSelect" listener="#{musteriBean.showImage()}" update=":panel" />
                <p:column headerText="ID">
                    <h:outputText value="#{img.id}" />
                </p:column>
            </p:dataTable>
        </h:form>
        <br />
        <h:form id="panel">
            <p:panelGrid  columns="1">
                <p:graphicImage value="#{musteriBean.secilenMusteriResimi}"/>
            </p:panelGrid>
        </h:form>
当我运行程序时

http://hizliresim.com/Y3lky6


我如何解决这个问题?我在等你的帮助。多谢各位

您不能像现在这样将图像嵌入到html中。 在html代码中,您必须只指向图像的url,并让浏览器下载图像。 图像url应如下所示:

http: //hizliresim.com/Y3lky6/readMyImage/1234


然后,您必须创建servlet“readMyImage”,从具有给定id的数据库映像读取数据,并将其提供给浏览器。

什么问题?你还没告诉我们问题出在哪里,我说了。我想在我的xhtml页面中添加图像。我哪里做错了?
http: //hizliresim.com/Y3lky6/readMyImage?imageId=1234