Topic: 文件下载的问题

  Print this page

1.文件下载的问题 Copy to clipboard
Posted by: newsletter
Posted on: 2006-05-24 10:51

我写了一个下载的程序,在本地机器上测试的时候是可以下载到文件的,但是在其他机器上打开IE登陆我的系统后,下载功能可以实现,可是下载文件的内容却为空!请各位高手指导一下.
String root = Coder.convertISO2UTF8(servlet.getServletContext().getRealPath("/"));
    String path = Coder.convertISO2UTF8(request.getParameter("path"));
    String name = request.getParameter("name");
    name=Coder.convertISO2UTF8(name);
    response.setContentType("unknown");
    response.addHeader("Content-Disposition", "filename=\"" + name + "\"");
    
    try
    {
      java.io.OutputStream os = response.getOutputStream();
      java.io.FileInputStream fis = new java.io.FileInputStream(root + path + name);

      byte[] b = new byte[1024];
      int i = 0;

      while ( (i = fis.read(b)) > 0 )
      {
       os.write(b, 0, i);
      }

      fis.close();
      os.flush();
      os.close();
    }
    catch ( Exception e )
    {
      e.printStackTrace();
    }

2.Re:文件下载的问题 [Re: newsletter] Copy to clipboard
Posted by: kkk
Posted on: 2006-05-31 15:07

我也写了个,可是连上传都实现不了.我不知哪错了.能帮忙看看吗??
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,com.jspsmart.upload.*" errorPage="" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<jsp:useBean id="mySmartupload" scope="page" class="com.jspsmart.upload.SmartUpload" />
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>上传文件</title>
</head>

<body>
<div align="center">
<p>文件上传
</p>
<hr>
<%
   int count=0;
   String destin="d:/tt";
   mySmartupload.initialize(pageContext);
   mySmartupload.upload();
   out.println(1);
String content=mySmartupload.getRequest().getParameter( "text1" );
   out.println(content);
   out.println(2);
   for(int i=0;i<mySmartupload.getFiles().getCount();i++)
   {
   out.println(3);
   com.jspsmart.upload.File myFile = mySmartupload.getFiles().getFileLight Bulb;
   if(!myFile.isMissing())
   {
    out.println(4);
     myFile.saveAs(destin+myFile.getFileName());
     out.println( " 文件名称"+myFile.getFieldName()+"<br>");
out.println( "文件大小 "+myFile.getSize()+"<br>");
out.println( "文件名称 "+myFile.getFileName()+"<br>");
out.println( "文件扩展名 "+myFile.getFileExt()+"<br>");
out.println( "文件大小 "+myFile.getFilePathName()+"<br>");
out.println( "文件路径 "+myFile.getFilePathName()+"<br>");
out.println( "文件类型 "+myFile.getContentType()+"<br>");
out.println( "contentdisp "+myFile.getContentDisp()+"<br>");
out.println( "MIME类型 "+myFile.getTypeMIME()+"<br>");

out.println( " </TABLE><BR> " );
      }
    }
%>
</div>
</body>
</html>
不知怎么搞的,就是实现不了呀.

3.Re:文件下载的问题 [Re: newsletter] Copy to clipboard
Posted by: shgshg
Posted on: 2006-06-08 10:45

你应该设置成xls类型啊: response.setContentType(".xls");,我是用的是专门写了一个配置文件作为路径的就可以了,保存在硬盘上就是*.xls


   Powered by Jute Powerful Forum® Version Jute 1.5.6 Ent
Copyright © 2002-2021 Cjsdn Team. All Righits Reserved. 闽ICP备05005120号-1
客服电话 18559299278    客服信箱 714923@qq.com    客服QQ 714923