<%@page contentType="text/html;charset=GBK" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
String fURL=(String)request.getAttribute("fURL");
String fname=(String)request.getAttribute("fname");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<%@page import="java.io.File"%>
<html>
<head>
<base href="<%=basePath%>">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<%
//String fname=request.getParameter("fname"); //fname的值从动态生成的下载超链接里获得
if(null==fURL||fURL.equals("")){
out.println("<script>alert('该文档不包含附件');history.back(-1);</script>");
return;
}
else
{
File file=new File(fURL);
if(!file.exists()){ //<font color=red>"+realPath+"</font>
out.println("<br><center><h2>该文件已不存在,请与管理员联系。</h2></center><br>");
out.println("文件路径:"+file.getAbsolutePath());
out.println("<center><input type='button' onclick='history.back(-1);' value='返回'></center>");
return;
}
// 新建一个SmartUpload对象
com.jspsmart.upload.SmartUpload su = new com.jspsmart.upload.SmartUpload();
// 初始化
su.initialize(pageContext);
// 设定contentDisposition为null以禁止浏览器自动打开文件,
//保证点击链接后是下载文件。若不设定,则下载的文件扩展名为
//doc时,浏览器将自动用word打开它。扩展名为pdf时,
//浏览器将用acrobat打开。
su.setContentDisposition(null);
// 下载文件(第一个参数:文件URL;
//第二个参数:文件内容类型,若为NULL或""为"application/x-msdownload")
//第三个参数为文件别名
su.downloadFile(fURL,null,fname);
//su.downloadFile("D:/export/txt/1yd2007-9-27.txt");
//以下两句很关键,使用完输出流以后调用他们,防止出现输出流错误
out.clear();
out = pageContext.pushBody();
}
%>
</body>
</html>