package com.cdd.servlet;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.jspsmart.upload.SmartUpload;
public class DownServlet extends HttpServlet {
/**
* Constructor of the object.
*/
public DownServlet() {
super();
}
/**
* Destruction of the servlet. <br>
*/
public void destroy() {
super.destroy(); // Just puts "destroy" string in log
// Put your code here
}
/**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request, response);
}
/**
* The doPost method of the servlet. <br>
* This method is called when a form has its tag value method equals to
* post.
*
* @param request
* the request send by the client to the server
* @param response
* the response send by the server to the client
* @throws ServletException
* if an error occurred
* @throws IOException
* if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String downfilename = request.getParameter("path"); //获取请求的文件地址
try {
String filename = new String(downfilename.getBytes("gbk"),
"ISO-8859-1");
if ((downfilename != null) && (filename != null)) { //判断要下载的文件是否为空
SmartUpload mydown = new SmartUpload();
mydown.initialize(getServletConfig(), request, response); //使用初始化方法
mydown.setContentDisposition(null); //弹出”文件下载“对话框
mydown.downloadFile(downfilename, filename); //调用文件下载方法
}
} catch (Exception e) {
RequestDispatcher rd = request.getRequestDispatcher("/index.jsp");
rd.forward(request, response);
}
}
/**
* Initialization of the servlet. <br>
*
* @throws ServletException
* if an error occurs
*/
public void init() throws ServletException {
// Put your code here
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
JSP实现文件下载---源码
共28个文件
css:2个
java:2个
jsp:2个
5星 · 超过95%的资源 需积分: 10 17 下载量 146 浏览量
2011-01-17
21:15:19
上传
评论
收藏 1.31MB RAR 举报
温馨提示
请先查看此网页 http://hi.baidu.com/g882/blog/item/e33b88ee8ceda2e9b3fb9525.html?timeStamp=1295270055240
资源推荐
资源详情
资源评论
收起资源包目录
文件下载.rar (28个子文件)
文件下载
21.02
.project 1KB
.settings
.jsdtscope 406B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 288B
WebRoot
css
style.css 2KB
WEB-INF
web.xml 805B
lib
jspSmartUpload.jar 16KB
classes
com
cdd
servlet
DownServlet.class 2KB
index.jsp 2KB
META-INF
MANIFEST.MF 39B
image
down1.bmp 988KB
down2.bmp 988KB
.myeclipse
src
com
cdd
servlet
DownServlet.java 3KB
.classpath 417B
21.03
.project 1KB
.settings
.jsdtscope 406B
org.eclipse.wst.jsdt.ui.superType.container 49B
org.eclipse.wst.jsdt.ui.superType.name 6B
.mymetadata 288B
WebRoot
css
style.css 2KB
WEB-INF
web.xml 804B
lib
classes
com
cdd
sevlet
DownServlet.class 2KB
index.jsp 2KB
META-INF
MANIFEST.MF 39B
11.mp3 110KB
.myeclipse
src
com
cdd
sevlet
DownServlet.java 2KB
.classpath 340B
共 28 条
- 1
资源评论
- 龙少有约2013-08-05总的来说还行,比我之前写的那个好用~
- jinxiongyi_12013-06-05写的不错,测试通过,写的很清晰。谢谢。
gg882
- 粉丝: 14
- 资源: 23
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功