2013年7月28日星期日

the servlet response.setHeader ("Content-Disposition", "attachment;Filename = ..") Download Issue

response.setContentType ("text / html");
/ / (replaced response.setContentType ("image / jpeg" ;); does not work)

response.setHeader ("Content-Disposition", "attachment; Filename = 011.jpg");
String path = this.getServletContext (). getRealPath ("/ file/011.jpg");

FileInputStream fis = new FileInputStream (path);
System.out.println (path);
int len ??= 0;
byte buffer [] = new byte [1024];

OutputStream os = response.getOutputStream ();
while ((len = fis.read ())> 0) {
os.write (buffer, 0, len);
}
os.close ();
fis.close ();
There are dozens of image size K, the pop-up box when downloading into hundreds B, for a few the next test is still the same file, the file becomes very small, after downloading can not open
- ---- Solution -------------------------------------------- < br> fis you did not even read buffer to
------ For reference only -------------------------- -------------
response.setContentType ("application / x-msdownload");
------ For reference only -------- -------------------------------
useless, still the same
------ For reference only ---------------------------------------
Ai Ai, sharply, tangled half , thought it was response.setContentType problem, thank
------ For reference only ------------------------- --------------

+ +
while ((len = fis.read ())> 0) {switch while ((len = fis.read (buffer))> 0) {
------ For reference only ---------------------------------------

+ +
while ((len = fis.read ())> 0) {switch while ((len = fis.read (buffer))> 0) { <> <> Well, right

1 条评论: