zoukankan      html  css  js  c++  java
  • 下载附件

    /**
    	 * 
    	 * 下载文件
    	 * 
    	 * @param id
    	 */
    	@RequestMapping(value="/downloadFile")
    	public void downloadFile(String id, HttpServletRequest request, HttpServletResponse response) {
    		//文件头信息
    		FileInfo fileinfo = licBO.findFileInfo(id);
    		if(fileinfo == null)
    		{
    			return;
    		}
    		String fileName = fileinfo.getFilename();
    		String path = licBO.findFilePath(id)+fileinfo.getFiletype();
    		response.setContentType("video/mpeg4; charset=utf-8");  
    	        // 定义输出文件头  
    		try {
    			response.setHeader("Content-Disposition", "attachment;filename=""  
    			            + URLEncoder.encode(fileName,"UTF-8") + """);
    	        File file = new File(path);  
    	        int len = (int) file.length();  
    	        byte[] buf = new byte[4096];  
    	        FileInputStream fis = new FileInputStream(file);  
    	        OutputStream out = response.getOutputStream();  
    	        len = fis.read(buf);  
    	        while (len != -1) {  
    	            out.write(buf, 0, len);  
    	            len = fis.read(buf);  
    	        }  
    	        out.flush();  
    	        out.close();  
    	        fis.close();  
    
    		} catch (Exception e) {
    			// TODO 自动生成 catch 块
    			logger.error(this, e);
    		}  
    	}
    

      前台下载

    window.top.showPic(URLS.filedownloadurl+'?id='+uploadobj[parentxxbh]);
    

      

  • 相关阅读:
    作业20181127-1 附加作业 软件工程原则的应用实例分析
    20181120-1 每周例行报告
    20181113-2 每周例行报告
    获奖感言
    作业 20181030-4 每周例行报告
    20181023-3 每周例行报告
    Weekly 13
    Weekly 10
    Weekly 11
    weekly 8
  • 原文地址:https://www.cnblogs.com/jassy/p/7060719.html
Copyright © 2011-2022 走看看