struts2文件下载

GroupExchangeNetworkFeedBack groupExchangeNetworkFeedBack = groupExchangeNetworkFeedBackBiz.getGroupExchangNetworkFeedBackById(feedBackId);
		String attachName = groupExchangeNetworkFeedBack.getAttachment();
		String attachUrl = groupExchangeNetworkFeedBack.getAttachmentUrl();
	           
		// 取得HttpServletResponse对象
        HttpServletResponse response = ServletActionContext.getResponse();
		//获取web应用程序在服务器上的路径须要访问ServletAPI
		ServletContext context = ServletActionContext.getServletContext();
		 // 通知浏览器如下载方式打开文件
      //  response.setHeader("content-disposition", "attachment;filename=" + URLEncoder.encode(exportFileName, "utf-8"));
		response.setHeader("content-disposition", "attachment;filename=" + new String(attachName.getBytes("gbk"), "ISO8859-1"));
      //  String realPath = context.getRealPath(attachUrl);
      
     // 构造子节输入流
        InputStream is = new FileInputStream(attachUrl + "/" + attachName);
     // 构造子节输出流
        OutputStream os = response.getOutputStream();
        byte[] b = new byte[1024];
        int len = 0;
        while ((len = is.read(b)) > 0) {
            os.write(b, 0, len);
        }
        is.close();
        os.close();
        
        return null;
相关文章
相关标签/搜索