admin 管理员组文章数量: 887169
2024年1月27日发(作者:ospf优先级是多少)
不好意思,最近工作忙,没上来看贴.我在这把代码给大家下:
Java代码
1.
2.
3.
4.
5.
6.
7.
9.
10.
11.
这是页面上的连接,我传了个路径和文件名
Java代码
1. <%
2. String filename = ameter("filename");//"";
3. String filepath = ameter("filepath");//"d:";
4. int i = 0;
5. tentType("application/octet-stream");
6. der("Content-Disposition","attachment;filename = "+filename);
7. putStream fileInputStream = new putStream(filepath+filename);
8. while((i= ()) != -1){
9. (i);
10. }
11.%>
这是被调用的,这个jsp就是执行直接下载文件的不管是txt还是word文档都可以直接下载
这个东东是我在一个专业编程杂志的网站花3块钱买的,嘿嘿.没办法,项目急用,今天上来看到有人需要赶紧发出来,希望3,4楼还能看到.
();
out = dy();
<%@page language="java" import=".*" pageEncoding="gb2312"%>
<%
tentType("application/x-download");//设置为下载application/x-download
String filenamedownload = "/";//即将下载的文件的相对路径
String filenamedisplay = "";//下载文件时显示的文件保存名称
filenamedisplay = (filenamedisplay,"UTF-8");
der("Content-Disposition","attachment;filename=" +
filenamedisplay);
try
{
RequestDispatcher dispatcher =
uestDispatcher(filenamedownload);
if(dispatcher != null)
{
d(request,response);
}
uffer();
}
catch(Exception e)
{
tackTrace();
}
finally
{
();
out = dy();
}
%>
<%@page language="java" contentType="application/x-msdownload"
import=".*,.*" pageEncoding="UTF-8"%>
<%
String txt ="实验";
n(txt);
tentType("application/txt");
der("Content-disposition",
"attachment;filename=");
BufferedOutputStream bos = null;
try {
bos = new BufferedOutputStream(putStream());
(es());
} catch (IOException e) {
throw e;
} finally {
if (bos != null)
();
();
out = dy();
}
%>
<%@page language="java" contentType="application/x-msdownload"
import=".*,.*" pageEncoding="gb2312"%><%
();//可以加也可以不加
tentType("application/x-download");
String filenamedownload = "D:";
String filenamedisplay = "";//系统解决方案.txt
filenamedisplay = (filenamedisplay,"UTF-8");
der("Content-Disposition","attachment;filename=" +
filenamedisplay);
OutputStream output = null;
FileInputStream fis = null;
try
{
output = putStream();
fis = new FileInputStream(filenamedownload);
byte[] b = new byte[1024];
int i = 0;
while((i = (b)) > 0)
{
(b, 0, i);
}
();
}
catch(Exception e)
{
n("Error!");
tackTrace();
}
finally
{
if(fis != null)
{
();
fis = null;
}
if(output != null)
{
();
output = null;
}
();
out = dy();
}
%>
版权声明:本文标题:下载txt 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.freenas.com.cn/free/1706328452h505485.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论