难做到 ,txt文件就是个很棘手的问题 ,临时转换扩展名可以试下
解决方案 »
- 为什么我在项目里引用了jquery却无法实现ajax呢
- 请问怎么用js读取php写的cookie啊? 感谢。
- 大家看看 做做好人 要怎么该才行啊
- 如何实现日期的动态选择?
- 关于scan后字符串length的问题
- 能不能用javascript代码清除当前页面的所有html代码,并写入新的html代码?
- 关于JAVASCRIPT的表格排序问题!
- javascript的打印有没有什么设置啊,为什么打印时总会有页眉和页脚(本页的名称和本页的网址),可不可以不要这些呢,烦恼中~
- jsp中更新页面下拉框数据同步的问题
- 求助:哪位大侠能告诉我如何用js实现一个类似VC里标签页的dd,万分感谢!
- 树状列表在本机调试的时候,显示不正常;用IE浏览的时候却正常.怎么回事啊?
- ASP?ID
不知道这个方法对你有什么提示作用没?
<%@ page contentType="text/html; charset=GBK"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ page import="java.io.File"%>
<%@page import="java.io.InputStream"%>
<%@page import="java.io.FileInputStream"%>
<%@page import="com.cpp.util.Constant"%>
<%
String path = request.getParameter("path") ;
if(path==null || "".equals(path)){
out.write("<script>") ;
out.write("alert('要下载的文件不存在');") ;
out.write("history.go(-1);") ;
out.write("</script>") ;
}
String realPath = Constant.BASE_DIR + path ;
File file = new File(realPath) ;
if(!file.exists()){
out.write("<script>") ;
out.write("alert('要下载的文件不存在');") ;
out.write("history.go(-1);") ;
out.write("</script>") ;
}else{
long l = file.length() ;
InputStream in = new FileInputStream(file) ;
String fs = file.getName() ;
if(in!=null){
response.reset();
response.setContentType("application/x-msdownload");
response.setHeader("Content-disposition","attachment; filename="+new String(fs.getBytes("GBK"),"iso8859-1"));
//以上输出文件元信息
response.setContentLength((int)l); //设置输入文件长度 byte[] b = new byte[2048];
int len = 0;
while((len=in.read(b)) >0)
response.getOutputStream().write(b,0,len); //向浏览器输出
in.close(); //关闭文件输入流
response.flushBuffer();
out.clear();
out = pageContext.pushBody();
}
}
%>这个download.jsp文件应该可以 要下载时后面加参数path=
无论任何文件均转化为输出流下载