"download1.jsp?filepath=d://&filename=1a.txt" >downloadtest1 _怎么从网站上下载txt">
赞
踩
- <meta http-equiv="Content-Type" content="text/html; charset=gbk">
- <HTML>
- <HEAD>
-
- </HEAD>
-
- <BODY>
- <a href = "download1.jsp?filepath=d://&filename=1a.txt" >downloadtest1</a>
-
- </BODY>
- </HTML>
这是页面上的连接,我传了个路径和文件名
- <%
- String filename = request.getParameter("filename");//"1a.txt";
- String filepath = request.getParameter("filepath");//"d://";
- int i = 0;
- response.setContentType("application/octet-stream");
- response.setHeader("Content-Disposition","attachment;filename = "+filename);
- java.io.FileInputStream fileInputStream = new java.io.FileInputStream(filepath+filename);
- while((i= fileInputStream.read()) != -1){
- out.write(i);
- }
- %>
这是被调用的download1.jsp,这个jsp就是执行直接下载文件的不管是txt还是word文档都可以直接下载
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。