<%@page contentType="text/html;charset=gb2312"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ page import="java.io.*"%>
<%
try{
response.setContentType("text/html");
javax.servlet.ServletOutputStream ou = response.getOutputStream();
//String filepath=(String)request.getAttribute("path");
String filepath="d://html5.zip";
File file = new File(filepath);
if (!file.exists()) {
System.out.println(file.getAbsolutePath() + " 文件不存在!");
return;
}
FileInputStream fileInputStream = new FileInputStream(file);
if (filepath != null && filepath.length() > 0) {
response.setContentType("application/x-msdownload");
response.setHeader("Content-Disposition", "attachment; filename=" + new String(file.getName().getBytes("gb2312"),"iso8859-1") + "");
if (fileInputStream != null) {
int filelen = fileInputStream.available();
byte a[] = new byte[filelen];
fileInputStream.read(a);
ou.write(a);
}
fileInputStream.close();
ou.close();
out.clear();
out = pageContext.pushBody();
}
}catch(Exception e){
e.printStackTrace();
}
%>