我想利用jspsmart组件,写一个sevelet,以实现对文件的下载?请大家帮忙
解决方案 »
- jquery的onkeypress事件
- strust 路径访问问题 在线等 请感兴趣的朋友都进来看一看
- Windows系统和SOLARIS部署同样的ear包,读取数据库中的中文问题
- 帮我看看这是什么错?应该怎么改?
- session问题
- 怎么将double转变成两位小数???
- Response 有没有其他的方法,我不想让网页自动定时刷新,而是想在有请求信息的时候刷新??
- 来者有分 初学者求助!
- 如何 iis+resin 能够运行?
- 在bean或servlet中如何得到jsp的文挡根目录,就像在jsp中用getServletContext().getRealPath("")的到的一样?
- request.getParameter 参数 字数 限制
- 急!!!!需要把windows media player播放方式改为flash播放
private ServletConfig config;
final public void init(ServletConfig config) throws ServletException {
this.config = config;
}
final public ServletConfig getServletConfig() {
return config;
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
String filename=request.getParameter("filename");//需要处理一下文件路径
response.addHeader("Content-Disposition","attachment;filename="+filename);
//SmartUpload su=new SmartUpload(getConfig().getServletContext(),request,response);
SmartUpload mySmartUpload=new SmartUpload();
try
{
mySmartUpload.initialize(config,request,response);
mySmartUpload.setContentDisposition(null);
mySmartUpload.downloadFile("d:\\"+filename);
}
catch(Exception e)
{}
}
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
this.doGet(req, resp);
}
}
这是我写的,但是不能实现文件的下载
// Initialization
mySmartUpload.initialize(pageContext);
// Download file
mySmartUpload.downloadFile("/upload/sample.zip");
// With a physical path
// mySmartUpload.downloadFile("c:\\temp\\sample.zip")
// With options
// mySmartUpload.downloadFile("/upload/sample.zip","application/x-zip-compressed","downloaded.zip")%>
mySmartUpload.initialize(pageContext);
// 设定contentDisposition为null以禁止浏览器自动打开文件,
//保证点击链接后是下载文件。若不设定,则下载的文件扩展名为txt时,直接在浏览器打开。
//文件类型为doc时,浏览器将自动用word打开它。扩展名为pdf时浏览器将用acrobat打开。
mySmartUpload.setContentDisposition(null);
// 下载文件
mySmartUpload.downloadFile("/upload/test.txt");%>
servlet就不知道了