从应用程序外部下载文件 [英] Downloading files from outside of the application
问题描述
这里的错误信息:
上下文路径:/ gestion-remboursement-web
Servlet路径:/pages/listDemandes.jsf
路径信息:null
查询字符串:null
堆栈跟踪
javax.servlet.ServletException
javax.faces.webapp.FacesServlet.service(FacesServlet.java:667)
io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86)
io.undertow.servlet.handlers.FilterHandler $ FilterChainImpl.doFilter(FilterHandler.java:130)
filters.LoginFilter.doFilter(LoginFilter.java:44)
这里是Xhtml代码:
< p:column style =text-align :centerheaderText =Télécharger>
< p:commandButton value =下载ajax =false
onclick =PrimeFaces.monitorDownload(start,stop);
icon =ui-icon-arrowthick-1-s>
< p:fileDownload value =#{fileDownloadView.file}/>
< f:setPropertyActionListener value =#{a}
target =#{demandeBean.demandeSelectionnee}/>
< / p:commandButton>
< / p:column>
这里是java Bean代码:
public class FileDownloadView {
private StreamedContent file;
public FileDownloadView(){
InputStream stream = FacesContext.getCurrentInstance()。getExternalContext()。getResourceAsStream(
http:// localhost:18080 / openCars / images / hichem .JPG);
file = new DefaultStreamedContent(stream,image / jpg,downloaded_optimus.jpg);
}
public StreamedContent getFile(){
return file;
}
}
遇到一些情况来获取pdf文件,使用 java.net.URL#openStream()喜欢
InputStream input = new URL( HTTP://本地主机:18080 / openCars /图像/ hichem.jpg).openStream();
file = new DefaultStreamedContent(stream,image / jpg,downloaded_optimus.jpg);
I'm using jsf 2.2 Primefaces 6.0 and i already implemented a solution to download an images from the ressources file inside the application and it works fine but when i try to download from the outside an error message will appear.I need help to can download from the outside of the application:
Here the error message :
Context Path:/gestion-remboursement-web Servlet Path:/pages/listDemandes.jsf Path Info:null Query String:null Stack Trace javax.servlet.ServletException javax.faces.webapp.FacesServlet.service(FacesServlet.java:667) io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:86) io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:130) filters.LoginFilter.doFilter(LoginFilter.java:44)
Here the Xhtml code:
<p:column style="text-align: center" headerText="Télécharger">
<p:commandButton value="Download" ajax="false"
onclick="PrimeFaces.monitorDownload(start, stop);"
icon="ui-icon-arrowthick-1-s">
<p:fileDownload value="#{fileDownloadView.file}" />
<f:setPropertyActionListener value="#{a}"
target="#{demandeBean.demandeSelectionnee}" />
</p:commandButton>
</p:column>
Here the java Bean code :
public class FileDownloadView {
private StreamedContent file;
public FileDownloadView() {
InputStream stream = FacesContext.getCurrentInstance().getExternalContext().getResourceAsStream(
"http://localhost:18080/openCars/images/hichem.jpg");
file = new DefaultStreamedContent(stream, "image/jpg", "downloaded_optimus.jpg");
}
public StreamedContent getFile() {
return file;
}
}
Similar kind of situation faced to get pdf files, solved using java.net.URL#openStream() like
InputStream input = new URL("http://localhost:18080/openCars/images/hichem.jpg").openStream();
file = new DefaultStreamedContent(stream, "image/jpg", "downloaded_optimus.jpg");
这篇关于从应用程序外部下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!