你会用servlet吗??
你先告诉我这个我就告诉你,嘿嘿
http://community.csdn.net/Expert/topic/5723/5723279.xml?temp=.808346
你先告诉我这个我就告诉你,嘿嘿
http://community.csdn.net/Expert/topic/5723/5723279.xml?temp=.808346
解决方案 »
- j2ee 语言将pdf发送到客户端浏览器
- 请问现在哪个短信接口好啊
- 高分求IBatis 多表聚合查询怎么写
- CXF写的webservice很奇怪的问题
- 关于只能输入数字的输入框问题
- 关于jboss4 与mssql 数据库的连接错误,在xp下的问题,急求,急,急,急,急,急,急,急,急,急,!!!!
- Hibernate 更新和删除操作失败
- tomcat 使用了开发模式,依然要重启服务器才能生效
- <logic:iterate>中迭代输出信息,如何在这过程输出<html:text>呢?
- 连接oracel时那个sid是什么?
- struts中一个页面如何引用bean
- 朋友急用人,占用宝地发此贴,谢谢斑竹留情:)美国公司急聘Java高手!
/**
* 压缩文件夹生成后缀名为".zip"的文件并下载
*
* @param folderPath,要压缩的文件夹的路径
* @param zipFilePath,压缩后文件的路径
* @param zipFileName,压缩后文件的名称
* @throws BizException
*/
public void DownZipFile(String folderPath, String zipFilePath,
String zipFileName) throws BizException {
File srcPath = new File(folderPath);
String outFilename = new String(zipFilePath);
int len = srcPath.listFiles().length;
String[] filenames = new String[len]; // 需压缩的文件夹中的文件名
byte[] buf = new byte[1024];
try {
File[] files = srcPath.listFiles();
for (int i = 0; i < len; i++) {
// if(!files[i].isDirectory())
filenames[i] = srcPath.getPath() + File.separator
+ files[i].getName();
}
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
outFilename));
for (int i = 0; i < filenames.length; i++) {
FileInputStream in = new FileInputStream(filenames[i]);
out.putNextEntry(new org.apache.tools.zip.ZipEntry(files[i]
.getName()));
int bufLen;
while ((bufLen = in.read(buf)) > 0) {
out.write(buf, 0, bufLen);
}
out.closeEntry();
in.close();
}
out.close();
} catch (IOException e) {
log.error(e.getMessage()
+ " occurred in compress fileList operation", e);
throw new BizException(new SystemMessage("文件夹:" + folderPath
+ " 生成压缩文件 " + zipFileName + " 失败 !"));
}
try {
MyFacesHelper.downLoadFile(new FileInputStream(zipFilePath),
zipFileName + ".zip", "application/x-download");
} catch (FileNotFoundException e) {
log
.error(e.getMessage()
+ " occurred in down zipfile operation", e);
throw new BizException(new SystemMessage("文件没有找到:" + zipFileName
+ ",路径:" + zipFilePath));
} catch (IOException e) {
log
.error(e.getMessage()
+ " occurred in down zipfile operation", e);
throw new BizException(new SystemMessage("输入输出异常!"));
}
}
/**
* 压缩文件夹生成后缀名为".zip"的文件并下载
*
* @param folderPath,要压缩的文件夹的路径
* @param zipFilePath,压缩后文件的路径
* @param zipFileName,压缩后文件的名称
* @throws BizException
*/
public void DownZipFile(String folderPath, String zipFilePath,
String zipFileName) throws BizException {
File srcPath = new File(folderPath);
String outFilename = new String(zipFilePath);
int len = srcPath.listFiles().length;
String[] filenames = new String[len]; // 需压缩的文件夹中的文件名
byte[] buf = new byte[1024];
try {
File[] files = srcPath.listFiles();
for (int i = 0; i < len; i++) {
// if(!files[i].isDirectory())
filenames[i] = srcPath.getPath() + File.separator
+ files[i].getName();
}
ZipOutputStream out = new ZipOutputStream(new FileOutputStream(
outFilename));
for (int i = 0; i < filenames.length; i++) {
FileInputStream in = new FileInputStream(filenames[i]);
out.putNextEntry(new org.apache.tools.zip.ZipEntry(files[i]
.getName()));
int bufLen;
while ((bufLen = in.read(buf)) > 0) {
out.write(buf, 0, bufLen);
}
out.closeEntry();
in.close();
}
out.close();
} catch (IOException e) {
log.error(e.getMessage()
+ " occurred in compress fileList operation", e);
throw new BizException(new SystemMessage("文件夹:" + folderPath
+ " 生成压缩文件 " + zipFileName + " 失败 !"));
}
try {
MyFacesHelper.downLoadFile(new FileInputStream(zipFilePath),
zipFileName + ".zip", "application/x-download");
} catch (FileNotFoundException e) {
log
.error(e.getMessage()
+ " occurred in down zipfile operation", e);
throw new BizException(new SystemMessage("文件没有找到:" + zipFileName
+ ",路径:" + zipFilePath));
} catch (IOException e) {
log
.error(e.getMessage()
+ " occurred in down zipfile operation", e);
throw new BizException(new SystemMessage("输入输出异常!"));
}
}-------------------------
很详细了
<a href="/..../..../xxx.zip"
onMouseOver="this.style.cursor='hand',this.style.color='#FF0000'"
onMouseOut="this.style.color='#006699'">点击下载</a>
<%@page contentType="text/html; charset=GBK" language="java" %>
<%@page import="java.util.*"%>
<%@page import="java.io.*"%>
<%@page import="java.net.*"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd";>
<%
request.setCharacterEncoding("GBK");
String fileNameWrite=request.getParameter("file");
String fileName=new String(request.getParameter("file").getBytes("iso-8859-1"),"GBK");
String sss=request.getRealPath("\\")+"files\\"+fileName;
System.out.println(sss);
if("1".equals(request.getParameter("downloadFlag"))){
response.setHeader("Content-disposition","attachment; filename="+fileNameWrite);
}else if("0".equals(request.getParameter("downloadFlag"))){
response.setContentType("application/ms-word");
}
BufferedInputStream bis = null;
BufferedOutputStream bos = null;
try {
bis = new BufferedInputStream(new FileInputStream(getServletContext().getRealPath("\\" +"files\\"+ fileName)));
bos = new BufferedOutputStream(response.getOutputStream()); byte[] buff = new byte[2048];
int bytesRead; while(-1 != (bytesRead = bis.read(buff, 0, buff.length))) {
bos.write(buff,0,bytesRead);
} } catch(final IOException e) {
System.out.println ( "IOException." + e ); } finally {
if (bis != null)
bis.close();
if (bos != null)
bos.close();
}
%>
--------------------------------------------
index.jsp<%@ page contentType="text/html; charset=GBK" %>
シシハァウヨ<br><p>
<a href="download.jsp?file=dow.rar&downloadFlag=1">download<a>
</p>