Http://elf8848.iteye.com/blog/640964
Http://elf8848.iteye.com/blog/275823
Struts2.xml Configuration:
application/octet-stream inputStream 409600 attachment;filename="${filename}"
ExportDBAction. java
ExportDBAction. hostinfectdao =. properties = success = }. filename =. flag =. errormessage = setSuccess (. success = InputStream getInputStream () = "IP, domain name, time "+" \ n "(Iterator iter = Object [] row = row [0 = row [1 = DateUtils. formatDateEx (Date) row [3 + "," + dns + "," + time + "\ n" ByteArrayInputStream stream = ByteArrayInputStream (export. toString (). getBytes ("gbk" main (String args []) = "1"
Js function requesting action:
= "ExportDB.action?filename="+filename+".csv&flag="+flag+"&contentType=application/octet-stream"
}
Previously, the IE browser automatically opened the file during download.
At that time, the attachment; filename = "$ {filename}" in struts. xml }"
Write: filename = "$ {filename }"
To download an object directly, we need to do two things,
The first thing is: Set the response content class to "application/octet-stream", which is case-insensitive.
The second thing is: Set the HTTP response header name to Content-Disposition and set the value to attachment and filename = theFileName. TheFileName is the default file name that appears in the File Download Dialog Box. It is usually the same as the downloaded file name, but it can also be different.
Jsp page implementation code:
Html code:
<% String filename = "MengxianhuiDocTest.doc"= "D:\\" response.setContentType("APPLICATION/OCTET-STREAM""Content-Disposition""attachment; filename=\"" + filename + "\"" java.io.FileInputStream fileInputStream = java.io.FileInputStream(filepath + ((i=fileInputStream.read()) != -1%>