文件下载
来源:互联网 发布:淘宝网有企业账号注册 编辑:程序博客网 时间:2024/05/07 22:14
<%@ page contentType="text/html;charset=utf-8" pageEncoding="utf-8"%>
<%@ page errorPage="../common/error.jsp"%>
<jsp:directive.page import="java.io.BufferedInputStream"/>
<jsp:directive.page import="java.io.FileInputStream"/>
<jsp:directive.page import="java.io.BufferedOutputStream"/>
<%@ include file="../common/common.jsp"%>
<jsp:directive.page import="com.winekee.common.util.StringHelper"/>
<jsp:directive.page import="com.winekee.common.db.domain.Main"/>
<jsp:directive.page import="java.util.Map"/>
<%
//下载内部共享信息的附件
String id=StringHelper.nvl(request.getParameter("id"));//信息ID
Map forummap=(Map)sqlMapper.queryForObject("selectBySql","select filepath from forum where id="+id);//查询出文件保存路径
try
{
response.setContentType("application/x-msdownload;");
String filepath=Main.homepath+ "/upload/forum/"+StringHelper.nvl(forummap.get("filepath")); //文件完整路径
//获取文件名
String filename=StringHelper.nvl(forummap.get("filepath")).substring(StringHelper.nvl(forummap.get("filepath")).lastIndexOf("/")+1,StringHelper.nvl(forummap.get("filepath")).length());
response.setHeader("Content-disposition","attachment; filename="+new String( filename.getBytes("gb2312"),"iso8859-1"));
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(filepath));
BufferedOutputStream bos=new BufferedOutputStream(response.getOutputStream());
//新建缓冲区
byte[] buff=new byte[2048];
int bytesRead;
while((bytesRead=bis.read(buff, 0, buff.length))!=-1)
{
bos.write(buff);
}
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}catch(Exception e)
{
e.printStackTrace();
StringHelper.stringEquals("","系统找不到指定的路径");
}finally
{
out.clear();
out = pageContext.pushBody();
}
%>
<%@ page errorPage="../common/error.jsp"%>
<jsp:directive.page import="java.io.BufferedInputStream"/>
<jsp:directive.page import="java.io.FileInputStream"/>
<jsp:directive.page import="java.io.BufferedOutputStream"/>
<%@ include file="../common/common.jsp"%>
<jsp:directive.page import="com.winekee.common.util.StringHelper"/>
<jsp:directive.page import="com.winekee.common.db.domain.Main"/>
<jsp:directive.page import="java.util.Map"/>
<%
//下载内部共享信息的附件
String id=StringHelper.nvl(request.getParameter("id"));//信息ID
Map forummap=(Map)sqlMapper.queryForObject("selectBySql","select filepath from forum where id="+id);//查询出文件保存路径
try
{
response.setContentType("application/x-msdownload;");
String filepath=Main.homepath+ "/upload/forum/"+StringHelper.nvl(forummap.get("filepath")); //文件完整路径
//获取文件名
String filename=StringHelper.nvl(forummap.get("filepath")).substring(StringHelper.nvl(forummap.get("filepath")).lastIndexOf("/")+1,StringHelper.nvl(forummap.get("filepath")).length());
response.setHeader("Content-disposition","attachment; filename="+new String( filename.getBytes("gb2312"),"iso8859-1"));
BufferedInputStream bis=new BufferedInputStream(new FileInputStream(filepath));
BufferedOutputStream bos=new BufferedOutputStream(response.getOutputStream());
//新建缓冲区
byte[] buff=new byte[2048];
int bytesRead;
while((bytesRead=bis.read(buff, 0, buff.length))!=-1)
{
bos.write(buff);
}
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}catch(Exception e)
{
e.printStackTrace();
StringHelper.stringEquals("","系统找不到指定的路径");
}finally
{
out.clear();
out = pageContext.pushBody();
}
%>
- 下载图片,下载文件
- 文件下载
- 文件下载
- 文件下载
- 文件下载
- 文件下载
- 文件下载
- 下载文件
- 文件下载
- 下载文件
- 文件下载
- 文件下载
- 下载文件
- 文件下载
- 下载文件
- 下载文件
- 文件下载
- 下载文件
- strlen和mb_strlen区别(php获得中英文混合字符长度)
- 去子夜大神那看看顺便拿个导航菜单看看
- fileupload上传
- inflate (int resource, ViewGroup root)关于root 这个参数的最佳解释
- 致国内提供安卓应用内容服务商的一封信
- 文件下载
- XML配置文件的读取--DOM4J
- Android实现开机自动运行程序(转)
- 更改windows 2008远程桌面端口号
- 【水晶玻璃鞋 12】 TCP三次握手/四次挥手详解
- 关于 man ls > 1.txt 乱码的解决
- 修改xml文件
- SQL常用语句一览
- How to Add/Update Store Procedure in EF