Escape Problem downloading Files form a Web / JSF Application
Today I stumbled into a problem with my JSF Web Application supporting File Upload/Download Functionality.
Everything works fine until some user uploaded files with "blank" in the filename e.g. "my fantastic long filename.doc" or files with german characters like "große datei mit wörtern.doc"
The Upload of sees files is no problem for my JSF up. But if a user tries to download such a file an error 404 occurs.
My JSF Implementation supports a typical form to download the files from a file list. It looks like this:
<h2>Download</h2>
<c:forEach var="attachment" items="#{workitemLobBean.files}">
<h:outputLink target="_blank"
value="#{facesContext.externalContext.requestContextPath}/Service/$file/#{attachment}">
<h:outputText value="#{attachment}" />
</h:outputLink>
<br />
</c:forEach>
So the filenames will be escaped into something like :
"my+fantastic+long+filename.doc"
which leads into the error 404. To avoid this escaping I used the following trick (not very nice but it works)
<h2>Download</h2>
<c:forEach var="attachment" items="#{workitemLobBean.files}">
<h:outputText escape="false" value="<a target='_balnk' href='" />
<h:outputText escape="false" value="#{facesContext.externalContext.requestContextPath}/Service/$file/#{attachment}" />
<h:outputText escape="false" value="'>#{attachment}</a>" />
<br />
</c:forEach>
If you find a better solution to escape filenems in JSF output let me know.
Posted at 10:42AM Mai 19, 2009
Posted by: Ralph
Category: General