怎么提供一个URL让别人下载小弟我的zip文件
如何提供一个URL让别人下载我的zip文件
1。在你的tomact /webapps/mywebpro 创建这些文件夹 /soft/update/然后下边放AAA.zip文件。
2。在你的index.jsp 中加入
<a href="down.jsp?filename=AAA.zip"> AAA文件</a>
3.将down.jsp 放至mywebpro 下.内容为
<%
response.reset();//可以加也可以不加
response.setContentType("application/x-download");
String filename=request.getParameter("filename");
String filenamedownload ="/soft/update/"+filename;
System.out.println(filenamedownload);
String filenamedisplay =filename;//系统解决方案
filenamedisplay = URLEncoder.encode(filenamedisplay,"UTF-8");
response.addHeader("Content-Disposition","attachment;filename=" + filenamedisplay);
OutputStream output = null;
FileInputStream fis = null;
try
{
output = response.getOutputStream();
fis = new FileInputStream(filenamedownload);
byte[] b = new byte[1024];
int i = 0;
while((i = fis.read(b)) > 0)
{
output.write(b, 0, i);
}
output.flush();
}
catch(Exception e)
{
System.out.println("Error!");
e.printStackTrace();
}
finally
{
if(fis != null)
{
fis.close();
fis = null;
}
if(output != null)
{
output.close();
output = null;
}
}
%>
方法二:
写个servlet将 zip文件的网络路径返回给浏览器就行了
1。在你的tomact /webapps/mywebpro 创建这些文件夹 /soft/update/然后下边放AAA.zip文件。
2。在你的index.jsp 中加入
<a href="down.jsp?filename=AAA.zip"> AAA文件</a>
3.将down.jsp 放至mywebpro 下.内容为
<%
response.reset();//可以加也可以不加
response.setContentType("application/x-download");
String filename=request.getParameter("filename");
String filenamedownload ="/soft/update/"+filename;
System.out.println(filenamedownload);
String filenamedisplay =filename;//系统解决方案
filenamedisplay = URLEncoder.encode(filenamedisplay,"UTF-8");
response.addHeader("Content-Disposition","attachment;filename=" + filenamedisplay);
OutputStream output = null;
FileInputStream fis = null;
try
{
output = response.getOutputStream();
fis = new FileInputStream(filenamedownload);
byte[] b = new byte[1024];
int i = 0;
while((i = fis.read(b)) > 0)
{
output.write(b, 0, i);
}
output.flush();
}
catch(Exception e)
{
System.out.println("Error!");
e.printStackTrace();
}
finally
{
if(fis != null)
{
fis.close();
fis = null;
}
if(output != null)
{
output.close();
output = null;
}
}
%>
方法二:
写个servlet将 zip文件的网络路径返回给浏览器就行了