Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/jsf/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Jsf p:上传文件不';不能使用pdf扩展,其他扩展(如png、docx、jpeg、gif)都不能使用?_Jsf_Primefaces - Fatal编程技术网

Jsf p:上传文件不';不能使用pdf扩展,其他扩展(如png、docx、jpeg、gif)都不能使用?

Jsf p:上传文件不';不能使用pdf扩展,其他扩展(如png、docx、jpeg、gif)都不能使用?,jsf,primefaces,Jsf,Primefaces,我不能存储超过10Mb的文件 主要的问题是为什么除了pdf文件之外没有其他文件??? 这是我的ManagedBean 文件上传功能:- public void fileUploadListener(FileUploadEvent e) throws IOException, Exception { this.file = e.getFile(); File oStream = new File("c:\\test.pdf"); cours

我不能存储超过10Mb的文件 主要的问题是为什么除了pdf文件之外没有其他文件??? 这是我的ManagedBean 文件上传功能:-

public void fileUploadListener(FileUploadEvent e) throws IOException, Exception {

    this.file = e.getFile();                
    File oStream = new File("c:\\test.pdf");
    courseResourceBean.update(item);
    oStream.createNewFile();
    Long sss = file.getSize();
    InputStream inputStream = file.getInputstream();
    FileOutputStream outputStream = new FileOutputStream(oStream);
    byte[] buffer = new byte[sss.byteValue()];
    int lenght;
    while ((lenght = inputStream.read(buffer)) != -1) {
        outputStream.write(buffer, 0, lenght);
    }
    outputStream.close();
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("File Uploaded Successfully" + file.getSize()));
    String extension = file.getContentType();

}
public void prepDownload(Long id) throws Exception {
    File files = new File("c:\\test.pdf");
    InputStream input = new FileInputStream(files);
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    setDownload(new DefaultStreamedContent(input, externalContext.getMimeType(files.getName()), files.getName()));
    System.out.println("PREP = " + download.getName());
}
文件下载功能:-

public void fileUploadListener(FileUploadEvent e) throws IOException, Exception {

    this.file = e.getFile();                
    File oStream = new File("c:\\test.pdf");
    courseResourceBean.update(item);
    oStream.createNewFile();
    Long sss = file.getSize();
    InputStream inputStream = file.getInputstream();
    FileOutputStream outputStream = new FileOutputStream(oStream);
    byte[] buffer = new byte[sss.byteValue()];
    int lenght;
    while ((lenght = inputStream.read(buffer)) != -1) {
        outputStream.write(buffer, 0, lenght);
    }
    outputStream.close();
    FacesContext.getCurrentInstance().addMessage(null, new FacesMessage("File Uploaded Successfully" + file.getSize()));
    String extension = file.getContentType();

}
public void prepDownload(Long id) throws Exception {
    File files = new File("c:\\test.pdf");
    InputStream input = new FileInputStream(files);
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    setDownload(new DefaultStreamedContent(input, externalContext.getMimeType(files.getName()), files.getName()));
    System.out.println("PREP = " + download.getName());
}
这是xhtml页面 上传:-

<p:outputLabel value="#{msg.courseName}, #{msg.inArabic}" style="text-align: right"/>
        <p:fileUpload value="#{courseResourceMB.file}" mode="advanced" sizeLimit="200000000000" 
                      fileUploadListener="#{courseResourceMB.fileUploadListener}" update="msg11" >


        </p:fileUpload>

唐拉德:-

<p:commandButton id="downloadLink" value="Download" actionListener="#{courseResourceMB.prepDownload(item.id)}" ajax="false"> 
                <p:fileDownload value="#{courseResourceMB.download}" />
            </p:commandButton>


在标题中注明“上传”,但在标签中注明“下载”。一个问题永远不会与两者都相关。。。如果上载失败,则无法尝试下载,如果上载成功但下载失败,则与上载无关。请改进你的问题。如果它与其他扩展也失败,则与“pdf”无关。上传文件做得很好,除了.pdf文件无法写入其文件。这是错误