`
everlxq
  • 浏览: 104190 次
  • 性别: Icon_minigender_1
  • 来自: 青岛
社区版块
存档分类
最新评论

文件下载方法

 
阅读更多
实体类  字段名

"ID" IS 'ID',
	"EID" IS '事件编号',
	"WJMC" IS '名称',
	"WJKZM" IS '扩展名',
	"CCLJ" IS '存储路径',
	"WJDX" IS '文件大小',
	"YXXZ" IS '允许下载',
	"XZCS" IS '下载次数' );


public void downloadFj() {
		String id = request.getParameter("id");
		if (StringUtils.isNotEmpty(id)) {
			Sjfjb sjfjb = sjfjbService.get(Long.valueOf(id));
			HttpServletResponse response = ServletActionContext.getResponse();
			response.setContentType(sjfjb.getContenttype());
			String tempname = null;
			try {
				tempname = URLEncoder.encode(sjfjb.getWjmc(), "UTF-8");
				response.setHeader("Content-disposition",
						"attachment; filename=\"" + tempname);//filename是下载后文件的名字  filename是属性 不可变
				ServletOutputStream outStream = response.getOutputStream();
				BufferedOutputStream bos = null;
				bos = new BufferedOutputStream(outStream);
				File srcFile = new File(EaModelContent.uploadfilepath
						+ File.separator + sjfjb.getEid() + File.separator
						+ sjfjb.getCclj());
				FileInputStream stream = new FileInputStream(srcFile);
				int bytesRead = 0;
				byte[] buffer = new byte[1024];
				while ((bytesRead = stream.read(buffer, 0, 1024)) != -1) {
					bos.write(buffer, 0, bytesRead);
				}
				bos.close();
				outStream.close();
				stream.close();

				sjfjb.setXzcs(sjfjb.getXzcs()==null?1:sjfjb.getXzcs() + 1);
				sjfjbService.save(sjfjb);// 下载次数
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}

类1

public static final String OPERATE_INSERT="新建";
	public static final String OPERATE_UPDATE="更新";
	public static final String OPERATE_DELETE="删除";
	public static final String OPERATE_DELETE1="删除1";
	
    public static Map<String,Table> logTableMap;
	
	public static LinkedHashMap<String, String> operations;
	
	public static LinkedHashMap<String, String> usertags;
	
	public static String uploadfilepath;
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics