Programming Tips - Java: let user download a file (from a website)

Date: 2020oct4 Language: Java Q. Java: let user download a file (from a website) A. Its the same in any language, just set Content-Disposition and Content-Description and the file will come to the user as a download instead of a webpage. In Java:
response.setHeader("Content-Disposition", "attachment; filename=hello.txt"); response.setHeader("Content-Description", "Text File"); HttpEntity entity = new EntityTemplate(producer); ((EntityTemplate)entity).setContentType("text/plain"); response.setEntity(entity);