服务器端:
p
ublic void doGet(HttpServletRequest req, HttpServletResponse resp)
t
hrows ServletException, IOException{
req.setCharacterEncoding("GBK");
// 新建一个SmartUpload对象
SmartUpload su = new SmartUpload();
su.in
ITialize(this.getServlet
config(),req,resp);
// 设定contentDisposition为null以禁止浏览器自动打开文件,
//保证点击链接后是下载文件。若不设定,则下载的
文件扩展名为
//doc时,浏览器将自动用word打开它。扩展名为p
DF时,
//浏览器将用acrobat打开。
su.setContentDisposition(null);
//下载文件
try {
su.downloadFile("D://upload/"+"
test.txt");
} catch (SmartUploadException e) {
// TODO Auto-generated catch block
e.
PRintStackTrace();
}
客户端:
<script>
function getFile(){
$.get("<%=basePath%>LoadFileServlet","",function(data){
alert(data);
});
}
</script>
<a href="
#" onclick="getFile()">getfile</a>