我目前正在研究 JSF PrimeFaces,我想下载我的项目名称“CV”文件夹中存在的文件,但这里面临的问题是下面的代码
上传文件:
<h:form enctype="multipart/form-data">
<p:fileUpload
fileUploadListener="#{fileUploadController.handleFileUploadCv}"
mode="advanced" update="messages"
allowTypes="/(\.|\/)(doc|docx)$/" />
<p:growl id="messages" showDetail="true" />
</h:form>
文件下载:
<h:form id="form11">
<p:commandButton id="downloadLink" value="Download Cv" ajax="false"
onclick="PrimeFaces.monitorDownload(start, stop)"
icon="ui-icon-arrowthichk-s">
<p:fileDownload value="#{fileDownloadController.file}" />
</p:commandButton>
</h:form>
这是控制器类:
import java.io.InputStream;
import org.primefaces.model.DefaultStreamedContent;
import org.primefaces.model.StreamedContent;
@ManagedBean
@SessionScoped
public class FileDownloadController {
private StreamedContent file;
public FileDownloadController() {
InputStream stream = ((ServletContext)FacesContext.getCurrentInstance().getExternalContext().getContext()).getResourceAsStream("D:/Final Year Project/displayjob-portlet/docroot/cv/Junaid.cv");
System.out.print("inside download111");
file = new DefaultStreamedContent(stream);
}
public StreamedContent getFile() {
return file;
}
}