Can JSP client download files directly to a default loc without "saveas"?
i don't want the browser user to be aware of the file's downloading. So, how should my JSP be modified to fullfill that functionality?
<%@page language="java" import="java.net.*,java.io.*" pageEncoding="gb2312"%>
<%response.reset();
response.setContentType("application/x-downloaddfdfdfdfdfdfdfdfd");
System.out.println(this.getClass().getClassLoader()
.getResource("/").getPath());
String filenamedownload = "f:/exampleDCI_1.xml";
String filenamedisplay = "exampleDCI_1.xml";
filenamedisplay = URLEncoder.encode(filenamedisplay, "UTF-8");
response.addHeader("Content-Disposition", "attachment;filename="
+ filenamedisplay);
OutputStream output = null;
FileInputStream fis = null;
try {
output = response.getOutputStream();
fis = new FileInputStream(filenamedownload);
byte[] b = new byte[1024];
int i = 0;
while ((i = fis.read(b)) > 0) {
output.write(b, 0, i);
}
output.flush();
} catch (Exception e) {
System.out.println("Error!");
e.printStackTrace();
} finally {
if (fis != null) {
fis.close();
fis = null;
}
if (output != null) {
output.close();
output = null;
}
}
%>

