上一篇:Javascript传递中文出现乱码问题 >>
用Servlet实现下载
/*
* DownLoad.java
*/
package com.zy.oa.util;
import java.io.*;
import java.text.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.net.*;
/**
* 实现下载功能
*/
public class DownLoad {
public void downLoad(HttpServletResponse response, String headName, String fileUrl) throws Exception{
Logger.log("begin download " + headName);
if (headName.endsWith(".jpg") || (headName.endsWith(".gif"))) {
//no need setting content type and header
} else if (headName.endsWith(".txt")) {
response.setContentType( "text;charset=GB2312");
response.setHeader("Content-disposition",
"attachment; filename=" + headName );
} else {
response.setContentType( "application/doc;charset=GB2312");
response.setHeader("Content-disposition",
"attachment; filename=" + headName );
}
String fileURL = fileUrl;
Logger.log(fileURL);
if(fileURL == null)
return;
try{
File file = new File(fileUrl);
FileInputStream bis = new FileInputStream(file);
OutputStream bos = response.getOutputStream();
byte[] buff = new byte[1024];
int readCount = 0;
int i = 0;
readCount = bis.read(buff);
while (readCount != -1){
bos.write(buff, 0, readCount);
readCount = bis.read(buff);
}
Logger.log("read finished!");
if (bis!=null)
bis.close();
if (bos!=null)
bos.close();
}catch(Exception e){
e.printStackTrace();
throw e;
}
}
}
下一篇:用web_xml控制Web应用的行为(下)转贴 >>
相关文章:
- · Web开发学习笔记
- · 用servlet显示图片
- · Servlet设计
- · 如何用jsp输出存在于oracle数据库Blob字段中的…
- · 关于JAVA的分页查询操作技术
- · 使用XML封装数据库操作语句的实现(完全版)-…
- · FC3 安装升级手记
- · 网上看到比较方便的vsftpd讲解
- · 子网掩码计算方法
- · 关于pasv模式中,数据端口由谁指定?
- · Vsftpd1.2.0的高级配置篇
- · Vsftpd1.2.0的基础配置篇
- · SERV-U 6002版安全设置全攻略(3)
- · SERV-U 6002版安全设置全攻略(2)
- · SERV-U 6002版安全设置全攻略(1)
- · SERV-U 6002版安全设置全攻略(4)
- · FTP的建立与维护
- · 用SSL加密增强FTP服务器安全性
- · 教你如何巧妙设定匿名FTP的安全
- · 创建IIS6.0下用户隔离模式FTP站点
- · Secure FTP:安全的企业级FTP服务器
- · BulletProof FTP Server:物美价廉
- · ArGoSoft FTP服务器:架设只要一分钟
- · FTP服务器架设--管理篇
- · FTP服务器架设--架设篇
- · FTP服务器架设--安全篇
- · serv-U FTP软件的攻击防守
- · FTP服务器快速架设全功略
- · IIS建立FTP就真的那么弱吗
- · 关于ftp服务程序中不安全因素研究
- · FTP服务器安全
- · FTP服务器端软件Serv-U教程(6)
- · FTP服务器端软件Serv-U教程(2)
- · FTP服务器端软件Serv-U教程(5)
- · FTP服务器端软件Serv-U教程(3)
- · FTP服务器端软件Serv-U教程(1)
- · FTP服务中允许上传权限存在的问题
- · 内网FTP服务器架设不完全解析
