Yesterday did a file from the service download function, how do not pop up the page, download box. After the query learned. There are two ways of
1.<a href= ' download path '/>
2.window.location.href = BasePath + "Downloadtemplate.do?template=huiyuan";
There are two ways to have this pop-up window
Hope can help, meet with me the same problem friend ~
A downloadable tool class that can be copied directly to the available
Public void DownloadFile (String filepath,string filename,httpservletresponse response) throws exception{
//uri URI = This.getclass (). getClassLoader (). GetResource (FilePath). Touri ();
File File = new file (FilePath);
//Empty response
Response.reset ();
//Set the header of response
Response.AddHeader ("Content-disposition", "Attachment;filename="
+ new String (Filename.getbytes ("GBK"), "iso-8859-1")); Files downloaded after transcoding do not appear garbled in Chinese
Response.AddHeader ("Content-length", "" "+ File.length ());
//Download the file in stream form
InputStream fis = new Bufferedinputstream (new FileInputStream (FilePath));
byte[] buffer = new byte[fis.available ()];
fis.read (buffer);
fis.close ();
outputstream toclient = new Bufferedoutputstream (Response.getoutputstream ());
toclient.write (buffer);
Toclient.flush ();
toclient.close ();
}
Java Web server file download (with download popup)