怎样实现统计某个文件被下载的次数? 最好有源码。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 BufferedOutputStream bos = null; boolean downFlag = true; File file = new File(storeFilePath); String filename = file.getName(); StringBuffer sb = new StringBuffer(50); sb.append("attachment; filename="); sb.append(filename); if (filename != null) { try { httpServletResponse.setContentType( "application/x-msdownload;charset=GB2312"); httpServletResponse.setHeader("Content-Disposition", new String(sb.toString() .getBytes(), "ISO8859-1")); //String tmp = "c:/" + filename; FileInputStream fis = new FileInputStream(storeFilePath); bos = new BufferedOutputStream(httpServletResponse.getOutputStream()); byte[] buffer = new byte[2048]; while (fis.read(buffer) != -1) { bos.write(buffer); } bos.write(buffer, 0, buffer.length); fis.close(); bos.close(); } catch (IOException e1) { //点了“取消”按钮 downFlag = false; } //下载成功,更新下载次数! //rs.close(); if (downFlag == true) { stmt = conn.prepareStatement(updateDownTimesSql); stmt.setInt(1, downLoadTimes + 1); stmt.execute(); } } 可以尝试这样: 用filter对下载文件的目录进行过滤,然后考虑看能不能分析出文件名,最后就是数据库操作! JSP页面中${}含义 怎样找出空字段? 菜鸟请教,一个留言板程序... 关于用使用flex开发webgame的问题 MyEclipse问题 web容器性能测试怎么做? 十万火及的小程序 高手给调通行吗? 急,新手求助!!!!!!!!!! 如何才能防止class文件被反编译? sendRedirect(url)的问题 日期时间转换的怪问题 在ibatis中可以动态设置查询条件,可否动态设置select的列?
boolean downFlag = true;
File file = new File(storeFilePath);
String filename = file.getName();
StringBuffer sb = new StringBuffer(50);
sb.append("attachment; filename=");
sb.append(filename);
if (filename != null) {
try {
httpServletResponse.setContentType(
"application/x-msdownload;charset=GB2312");
httpServletResponse.setHeader("Content-Disposition",
new String(sb.toString()
.getBytes(), "ISO8859-1"));
//String tmp = "c:/" + filename;
FileInputStream fis = new FileInputStream(storeFilePath);
bos = new BufferedOutputStream(httpServletResponse.getOutputStream());
byte[] buffer = new byte[2048];
while (fis.read(buffer) != -1) {
bos.write(buffer);
} bos.write(buffer, 0, buffer.length); fis.close();
bos.close();
}
catch (IOException e1) { //点了“取消”按钮
downFlag = false;
}
//下载成功,更新下载次数!
//rs.close();
if (downFlag == true) {
stmt = conn.prepareStatement(updateDownTimesSql);
stmt.setInt(1, downLoadTimes + 1);
stmt.execute(); }
}
用filter对下载文件的目录进行过滤,然后考虑看能不能分析出文件名,最后就是数据库操作!