• Post Reply Bookmark Topic Watch Topic
  • New Topic

getting an empty file when downoalding : jsf 2.2  RSS feed

 
fatima zahra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I want to downoald a file stored in system directory but when downloading the file in jsf page I get it empty. this is my xhtml page :

and my managed bean :
 
Jaikiran Pai
Sheriff
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you sure the file exists? What happens if you add an explicit check for the existence of the file:



The reason it might be streaming an empty file is because as per the javadoc of File.length() http://docs.oracle.com/javase/7/docs/api/java/io/File.html#length%28%29:


Returns:
The length, in bytes, of the file denoted by this abstract pathname, or 0L if the file does not exist. Some operating systems may return 0L for pathnames denoting system-dependent entities such as devices or pipes.


You use the length() to set the content length of the response, which I guess is being set to 0 due to the absence of the file.
 
fatima zahra
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
thanks for reply yes the file does not exist, a problem of extension, there is no document with name contacts.doc, the correct name is contacts.docx.
 
Tim Holloway
Bartender
Posts: 18531
61
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I do not recommend using JSF to generate downloads. It isn't designed for that purpose. You're better off using a standard servlet or JSP for that part of the web application.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!