Using JSP? Just place a HTML <a> element with a valid URL to the file in question to represent a download link. If the file isn´t exposed in public, let the URL point to a servlet which streams the file to the response.
Edit: the darn forum engine was parsing the <a> element in the message &%"#$ .. Disabling HTML in this message.
I see that the code snippet in question has been modified. It doesn't matter. Doing any Java in a JSP, especially something like this, is a bad, bad, and did I mention BAD idea. It will be fragile and error-prone. Just don't do it.
Venkat Sadasivam wrote:There is no harm in giving possible ways.
Showing code that demonstrates poor practices may lead people, especially novices, to think that such code is ok to emulate. You can expect that the more senior developers will point out when such code is posted.