- <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>
<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);
- }
- %>
<%
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文档都可以直接下载