--test.jsp--
<%@page import="java.io.FileNotFoundException"%> <%@ page contentType="text/html;charset=gb2312" import="com.jspsmart.upload.*" %> <%@ page language="java" import="java.net.URLDecoder"%>
<% String ct_path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+ct_path+"/";
request.setCharacterEncoding("UTF-8");
String path = (String)request.getAttribute("path"); // 新建一个SmartUpload对象
try{ SmartUpload su = new SmartUpload();
// 设定contentDisposition为null以禁止浏览器自动打开文件,
//保证点击链接后是下载文件。若不设定,则下载的文件扩展名为
su.initialize(pageContext);
su.setContentDisposition(null);
su.downloadFile(path);
//downloadFile(String sourceFilePathName,String contentType,String destFileName)
//其中,sourceFilePathName为要下载的文件名(带目录的文件全名),contentType为内容类型(MIME格式的文件类型信息,可被浏览器识别),destFileName为下载后默认的另存文件名。
//以上方法为下载时修改文件名的方法-此处为公共下载方法,暂不按文件名下载 如需实现,请各业务回传各自实现
//su.downloadFile(s, s1)
out.clear();
out = pageContext.pushBody();
}catch(FileNotFoundException e)
{ %> <
html>
<head>
<style type='text/css'>
input { FONT-SIZE: 12px }
td { FONT-SIZE: 12px }
.p2 { FONT-SIZE: 12px }
.p6 { FONT-SIZE: 12px; COLOR: #1b6ad8 }
a { COLOR: #1b6ad8; TEXT-DECORATION: none }
a:hover { COLOR: red }
</style>
</head>
<body οncοntextmenu="return false" onselectstart="return false">
<p align='center'> </p>
<p align='center'> </p>
<table cellSpacing="0" cellPadding="0" width="540" align="center" border="0">
<tbody>
<tr>
<td vAlign='top' height="270">
<div align="center"><br><img height="211" src="../images/email/error.gif" width="329"/><br><br> <table cellSpacing="0" cellPadding="0" width="80%" border="0"> <tbody>
<tr>
<td><font class='p2'> <font color=#ff0000><img height=13 src="../images/email/emessage.gif" width=12/> :此附件未找到,或者可能已被管理员删除</font></font></td>
</tr>
<tr> <td height="8"></td> <td height="5"></td>
<tr> <td align='middle'> <center> <table cellSpacing="0" cellPadding="0" width="480" border="0"> <tbody>
<tr> <td width="6"><img height=26 src="../images/email/left.gif" width="7"></td> <td background=../images/email/bg.gif> <div align="center"><font class="p6"><a href="<%=basePath%>login.do">返回首页</a> | <a href="javascript:history.go(-1)">返回出错页</a> | <a href="javascript:window.close()">关闭本页</a></font> </div></td>
<td width="7"><img src="../images/email/right.gif"></td></tr></tbody></table></center></td></tr></tbody></table> <p align='center'> </p> <p align='center'> </p> </body>
</html>
<% } %>
使用:
<a href="/**/test.jsp">**风险揭示书.pdf</a>