Generate URL from Visual Force.

You do not need to write complicated apex code to expose attachment download to user. Here is an example how to do that directly on page.

<apex:outputLink value="{!URLFOR($Action.Attachment.Download, attDlId)}" 
    target="_blank">Click on this link to download your file<b>{!attDlName}</b>

This formula requires at least one parameter "attDlID" which is attachment Id.
Optionally you may use file name, then "attDlName" must contain string with name.

From Controller site you need only deliver values fro this variables.

public Id attDlId { get; set; }
public String attDlName { get; set; } 


© Paweł Woźniak