1.客戶端:
var realTimeUserChartPanel = Ext.create('Ext.panel.Panel', {
title: '在線用戶圖表1',
width: 200,
items:[{
xtype:'button',
text: 'download',
href:"realTime/download",
hrefTarget:"_self"
}]
});
2.服務器:@RequestMapping(value = "/download")
public void downloadFile(HttpServletResponse response){
String fileName = "/Users/lixin/tmp/result.txt";
response.setCharacterEncoding("utf-8");
response.setContentType("multipart/form-data");
response.setHeader("Content-Disposition", "attachment;fileName="+fileName);
try {
File file=new File(fileName);
System.out.println(file.getAbsolutePath());
InputStream inputStream=new FileInputStream(file);
OutputStream os=response.getOutputStream();
byte[] b=new byte[1024];
int length;
while((length=inputStream.read(b))>0){
os.write(b,0,length);
}
inputStream.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}