首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

java附件上载

2012-11-08 
java附件下载/* * 附件下载 */@RequestMapping(/download)public void downloadPost(HttpServletRespons

java附件下载
/*
* 附件下载
*/
@RequestMapping("/download")
public void downloadPost(HttpServletResponse response,HttpServletRequest request){

BufferedOutputStream bos = null;      
    try {
InputStream is = AttendanceController.class.getClassLoader()
.getResourceAsStream("/kaoqin.csv");

String disposition = "attachment;filename="
+ URLEncoder.encode("考勤模板.csv", "UTF-8");//注意(1)
   
response.setContentType("application/x-msdownload;charset=UTF-8");//注意(2) text/plain

response.setHeader("Content-disposition", disposition);

bos = new BufferedOutputStream(response.getOutputStream());

byte[] buffer = new byte[2048];

while (is.read(buffer) != -1) {

bos.write(buffer);

//bos.flush();
}

bos.close();

is.close();

} catch (Exception e) {

throw new RuntimeException(e);
}
    }
---------------------------------
csv文件在src目录下
----------------------------------
<a href="${path}/routine/attendance/index/download">模板下载</a>

热点排行