阅读背景:

关于文件下载自己忽略的文件中文命名。。。

来源:互联网 
public void download() throws Exception {
		HttpServletResponse response= ServletActionContext.getResponse();
		HttpServletRequest request =ServletActionContext.getRequest();
		 String path = request.getSession().getServletContext().getRealPath("/")+"excel\"+"empinport.xls";
		 String fileName="人员批量导入模板.xls";
		 InputStream inStream = new FileInputStream(path);// 文件的存放路径  
		 	response.reset();
	        response.setContentType("bin");
	        response.setHeader( "Content-Disposition", "attachment;filename=" + new String(fileName.getBytes("gb2312"), "ISO8859-1" ) );  
	        // 循环取出流中的数据
	        byte[] b = new byte[100];
	        int len;
	        try {
	            while ((len = inStream.read(b)) > 0)
	                response.getOutputStream().write(b, 0, len);
	            inStream.close();
	        } catch (IOException e) {
	            e.printStackTrace();
	        }
		}
public void download() throws Exception {
	



你的当前访问异常,请进行认证后继续阅读剩余内容。

分享到: