作为搜索应用程序的一部分,我希望用户能够下载将结果显示为CSV文件的报告。我有以下方法:
public void downloadCustomerResults(String customer) {
String output = "";
output += produceCustomerID(customer);
output += produceCustomerAddress(customer);
output += produceCustomerContactDetails(customer);
output += produceOrderHeader(customer);
output += producePayments(customer);
// Writes to server desktop,not user desktop.
try {
Writer fileWriter = new FileWriter("C:\\Users\\username\\Desktop\\SAR" + customer + "C.csv");
fileWriter.write(output);
fileWriter.flush();
fileWriter.close();
} catch (IOException e) {
e.printStackTrace();
}
}
这会将文件下载到运行服务器的计算机的桌面上,而不是用户的桌面上(通过Tomcat上的JSP访问应用程序)。如何更改文件路径字符串以将此下载下载到用户的桌面?还是我必须将文件传递给JSP,以便用户通过他们的浏览器下载?
谢谢。