<a href="xxx.zip">download</a>

解决方案 »

  1.   

    smartupload这个很好的,去下载一个
    http://www.jspsmart.com/scripts/download/downloadfree.asp?product=jspSmartUpload&L=EN
      

  2.   

    不知道你是什么样的下载啊?
    如果普通文件下载的话,<a href="filename">download</a>就可以啊。
    如果下载数据库大字段,可以用读取二进制流的方式。
    也可以用上传下载组件。
      

  3.   

    系统不能识别的格式(zip等)<a href="xxx.zip">download</a>就可以下载
    但如果系统能够识别(txt等))<a href="xxx.zip">download</a>就会直接在ie打开
    此时需要:在文件头上加上:
    response.setContentType("APPLICATION/OCTET-STREAM");
    response.setHeader("Content-Disposition","attachment; filename=" + filepath + filename);
      

  4.   

    我用的是TOMCAT服务器,如果文件名是中文的话就打不开是乱码还请指教。
      

  5.   

    import java.io.*;
    public class FileDownLoad {  public FileDownLoad() {
      }
      public void fileDown(String aFileName,javax.servlet.http.HttpServletResponse response) throws Exception {
        java.io.BufferedInputStream iin;
        BufferedOutputStream dout;
        try {
           File ff=new File(aFileName);
           if(!ff.exists()){
             throw new Exception("对不起! 您下载的文件不存在");
           }else{
             byte[] buffer;
             int length=(new Long(ff.length())).intValue();
             buffer=new byte[length];
             try{
                 iin=new BufferedInputStream(new java.io.FileInputStream(ff));
                  //设置类型和头信息
                response.setContentType( "application/octet-stream" ); // MIME type for pdf doc
                int pos=aFileName.lastIndexOf("/");
                aFileName=aFileName.substring(pos+1);
    response.setHeader("Content-disposition", "attachment; filename="+aFileName);
                //传送数据
                dout = new BufferedOutputStream( response.getOutputStream());
                int once = 0;
                int total = 0;
                while ((total<length) && (once>=0)) {
                   once = iin.read(buffer,total,length);
                   total += once;
                   dout.write(buffer,0,length);
                }
                if(iin!=null){   iin.close();}
                if(dout!=null){  dout.close();}
              }catch(Exception ex){
                 throw new Exception("文件下载过程中出现错误! ");
              }
            }
          }catch(Exception ex) {
             throw new Exception("文件下载过程中出现错误! ");
          }
       }
    }
    --------------------
    <%@ page import="java.io.*,SqlData,FileDownLoad,Utility,java.util.*"%><%@ page  language="java"  contentType="text/html;charset=gb2312"%><jsp:useBean id="fload" scope="page" class="FileDownLoad" /><%String username="";if (session.getValue("username")==null){%><script>window.open("/mail/webmail/login.htm","_top");</script><%}else{username=session.getValue("username").toString();}String cd=request.getRequestURI();cd=cd.substring(cd.lastIndexOf('/')+1);String path=application.getRealPath(cd);int lastSlash=path.lastIndexOf('\\');path=path.substring(0,lastSlash);String filename=path+"/mail/affix/"+username+"/"+request.getParameter("affixname");if(filename!=null)  fload.fileDown(filename,response);%>
    ------------------
    <a href="+java.net.URLEncoder.encode(RS.getString("filename"))+">RS.getString("filename")
    download.jsp文件,请不要用硬回车,要一行写下来,修改相应的路经传递给FILEDOWNLOAD类就可以了
      

  6.   

    tomcat对中文文件名基本上没办法