导出功能

public void downloadD(HttpServletRequest request, HttpServletResponse res,
			String contractName, String contractPath) throws IOException {
		// FileAttach fileAttach = fileAttachService.getFileAttachById(fileId);
		OutputStream os = res.getOutputStream();
		try {
			res.reset();
			String fileName = URLEncoder.encode(contractName, "UTF-8");  
	        /* 
	         * see http://support.microsoft.com/default.aspx?kbid=816868 
	         */  
	        if (fileName.length() > 150) {  
	            String guessCharset = "gb2312"; /*根据request的locale 得出可能的编码,中文操做系统一般是gb2312*/  
	            fileName = new String(contractName.getBytes(guessCharset), "ISO8859-1");   
	        }  
	        
	        
			res.setHeader("Content-Disposition", "attachment; filename="
					+ fileName);
			res.setContentType("application/octet-stream; charset=utf-8");
			String path = request.getSession().getServletContext()
					.getRealPath("/");
			File dirPath = new File(path +"/"+ contractPath);
			os.write(FileUtils.readFileToByteArray(dirPath));
			os.flush();
		} finally {
			if (os != null) {
				os.close();
			}
		}
	}
相关文章
相关标签/搜索