Niko
Niko

Reputation: 1094

JSF rename file on download

I have several to download a file, but I need some function which renames the file to be downloaded.

Is there a way to download a file, e.g. which is named on server "123.txt" and when the user downloads it, it saves it as "onetwothree.txt"? (e.g. like a sort of filter beween). i need this becaue of some charset encoding problems on the server

any help appreciated!

Upvotes: 0

Views: 157

Answers (1)

Luiggi Mendoza
Luiggi Mendoza

Reputation: 85779

When downloading the file, change the Content-Disposition to attachment; filename="<your_name_for_the_file_to_download>". In code:

String newName = ...;
response.addHeader("Content-Disposition", "attachment; filename=\"" + newName + "\"");

Upvotes: 1

Related Questions