d:\work 下是word 或excel文件
问题是:用jsp怎么做一个页面,把d:\work下
的文件都列出来,点击其中一个
会弹出打开还是另存为的对话框?
解决方案 »
- Struts2 配置问题???高手请进
- 请问如何让title居中?
- JSP中声明的例子
- 后台发布文件问题?
- 请教一个session的问题!
- 怎样把数据库中的 <Binary> 读出来?
- Win98下,jdk+tomcat+mysql,怎样运行JSP?
- 请问在JSP中如何访问oracle中自己创建的函数?
- 请问,有谁读过《Servlet与Jsp核心技术》Written by Marty Hall ?
- 如果开发一个门户网站 代码的具体流程是怎么样的?
- 请教com.jspsmart.upload.SmartUploadException:
- jar包和classes的区别??(jar包可用,class不可用)
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition","attachment; "+"filename="+ new String(filename.getBytes("gb2312"),"iso8859-1"));
//String filepath = "D:\\Apache Software Foundation\\Tomcat 5.5\\webapps\\webModule\\tempdb\\";
bis =new java.io.BufferedInputStream(new java.io.FileInputStream(config.getServletContext().getRealPath("tempdb/"+filename)));
bos=new java.io.BufferedOutputStream(response.getOutputStream());
byte[] buff = new byte[2048];
int bytesRead;
while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
{
bos.write(buff,0,bytesRead);
}
bis.close();
bos.close();
File f=new File(config.getServletContext().getRealPath("tempdb/"+filename));
f.delete(); }
catch (SQLException ex) {
ex.printStackTrace();
}
看看这个 http://www.haolla.com/girls/index.asp
http://haolla.com/wy
File f=new File();可以列出文件。
下载文件,就用其它组件,比如jspsmartupload等。
String[] fs = dir.list();
for (int i = 0; i < fs.length; i++) {
if (fs[i].indexOf(".") != -1)
System.out.println(fs[i]); }
然后在页面把fs[i]做个超链就行了