Jsf p:上传文件不';不能使用pdf扩展,其他扩展(如png、docx、jpeg、gif)都不能使用?
我不能存储超过10Mb的文件 主要的问题是为什么除了pdf文件之外没有其他文件??? 这是我的ManagedBean 文件上传功能:-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
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文件无法写入其文件。这是错误