Hi I am trying to implement pdf file download functionality by this way .
/* test.xhtml*/
<p:commandButton actionListener="#{backingBean.download}" update=":form"/>
/ BackingBean.java /
public Class BackkingBean implements serializable{
@ManagedBean
@ViewScoped
public void download(){
String uri = "http://173.24.57.274:8080/ROOT/html/xml/Test new_02.pdf";
URL url = new URL(uri);
File destination = new File("C:/Documents and Settings/microsoft/My Documents/Downloads/sample.pdf");
FileUtils.copyURLToFile(url, destination);
}
}
But when I am clicking on download button I am getting below error.
Caused by: java.io.IOException: Server returned HTTP response code: 505 for URL:
http://173.24.57.274:8080/ROOT/html/xml/Test new_02.pdf
I have gone some stackoverflow posts regarding this error but did'nt find any solution which work for me.
What I am missing? How can overcome from this problem.
You should try and encode the URL value. If I spy correctly, there seems to be a Space value within the name of the PDF file. ie "Test new_02.pdf". Encoding the URL using URLEncoder can eliminate issue with "special characters" within the URL and it is good practice to encode URL in java applications
Take a look at http://docs.oracle.com/javase/6/docs/api/java/net/URLEncoder.html
And read the documentation carefully to figure out how to encode the space character.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.