无法在iframe JSF中显示pdf

无法在iframe JSF中显示pdf,jsf,iframe,jsf-2,primefaces,Jsf,Iframe,Jsf 2,Primefaces,我让用户上传一个文件并将其存储 List<Meetingsattachment> mal= new ArrayList<Meetingsattachment>(); meeting.setMeetingsattachments(mal); Random rand=new Random(); int num=Math.abs(rand.nextInt()); String dirname="/path/to/files/"+meeting.

我让用户上传一个文件并将其存储

List<Meetingsattachment> mal= new ArrayList<Meetingsattachment>();
    meeting.setMeetingsattachments(mal);

    Random rand=new Random();
    int num=Math.abs(rand.nextInt());
    String dirname="/path/to/files/"+meeting.getDescription()+"-"+num;

    File dir= new File(dirname);
    System.out.println(dir.getAbsolutePath());
     if(! dir.exists()) 
          dir.mkdir();

     for(UploadedFile uf:ufl){
         Meetingsattachment ma=new Meetingsattachment();
         ma.setAttachment(dirname+"/"+uf.getFileName());
         File file = new File(dirname+"/"+uf.getFileName());


            try (FileOutputStream fop = new FileOutputStream(file)) {

                // if file doesn't exists, then create it
                if (!file.exists()) {
                    file.createNewFile();
                }

                // get the content in bytes

                fop.write(IOUtils.toByteArray(uf.getInputstream()));
                fop.flush();
                fop.close();
                meeting.addMeetingsattachment(ma);
                System.out.println("Done");

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


     }

    int meetingid=mrm.addMeeting(meeting);


    return "meetings?faces-redirect=true";
在jsf中

<ui:repeat var="meetattachment" value="#{meet.meetingsattachments}">
                <h:outputText value="#{meetattachment.attachment}" />

                <p:commandButton icon="ui-icon-arrowthickstop-1-s"

                        onclick="PrimeFaces.monitorDownload(showStatus, hideStatus)"
                        actionListener="#{meetBean.buttonAction}">
                        <f:attribute name="attachment" value="#{meetattachment}"></f:attribute>
                        <p:fileDownload value="#{meetBean.file}" />
                    </p:commandButton>
因此,我认为问题在于它试图用来查找文件的路径,根据我的理解,如果我使用相对路径/path/to/files存储文件,那么文件的实际路径是C:\path\to\files

我尝试硬编码值,只是为了测试

<h:outputLink value="C:\path\to\files\t2-672409104\1.pdf">

我收到一条消息说它无法理解协议C


因此,我的问题基本上是如何提供这些文件的路径,以便在一个框架中打开它们,jsf处理链接的方式是不同的。这就是您获取“未找到文件”错误的原因。如果要在iframe中打开文件,则需要做一些额外的工作。有一个pdfjs库,您可以下载它并使用它在iframe中显示pdf。在primefaces中,有一个组件可以做到这一点。您可以使用primefaces源来查看如何完成相同的操作。如果您需要更多信息或完整的手持,请务必让我知道。

对不起,这个答案毫无帮助。这是一个过于宽泛和模糊的明显的混乱。如果你不能具体回答,但只能在黑暗中拍摄一些照片,请发表评论而不是回答。对不起……请记住这一点。
<ui:repeat var="meetattachment" value="#{meet.meetingsattachments}">
                <h:outputText value="#{meetattachment.attachment}" />                   
                    <p:lightBox iframe="true">
                    <h:outputLink value="#{meetattachment.getAttachment()}">
                    preview2
                    </h:outputLink>
                    </p:lightBox>


                    <br />
            </ui:repeat>
GET 
http://localhost:8080/path/to/files/t2-672409104/1.pdf not found
<h:outputLink value="C:\path\to\files\t2-672409104\1.pdf">