在jsp页面上链接的地址指向rar文件  点链接的时候不能弹出保存的窗口  而是出现一个乱码的页面  该怎么处理这样的东西

解决方案 »

  1.   

    需要另写一个download.jsp文件,如下:<HEAD>
    <%@ page 
    language="java"
    contentType="text/html; charset=GBK"
    pageEncoding="GBK"
    %><TITLE>download.jsp</TITLE>
    </HEAD>
    <BODY>
    <%
    java.io.BufferedInputStream bis=null;
    java.io.BufferedOutputStream  bos=null;
    try
    {
    String filename = new String(request.getParameter("filename").getBytes("ISO8859_1"));
    String path = new String(request.getParameter("path").getBytes("ISO8859_1"));;

    response.setContentType("application/x-msdownload");
    response.setHeader("Content-disposition", "attachment; filename=" + new String(filename.getBytes("gb2312"), "iso8859-1")); bis = new java.io.BufferedInputStream(new java.io.FileInputStream(config.getServletContext().getRealPath(path + filename)));
    bos = new java.io.BufferedOutputStream(response.getOutputStream()); 

    byte[] buff = new byte[2048];
    int bytesRead;
    while(-1 != (bytesRead = bis.read(buff, 0, buff.length)))
    {
    bos.write(buff, 0, bytesRead);
    }
    }
    catch(Exception e)
    {
    e.printStackTrace();
    }
    finally
    {
    if (bis != null)
    {
    bis.close();
    }

    if (bos != null)
    {
    bos.close();
    }
    }
    %> 
    </BODY>
    </HTML>test.jsp:
    <BODY>
    <A href="download.jsp?filename=新建.rar&path=/">测试</A>
    </BODY>
    在test.jsp点击"测试",即可下载"新建.rar".
      

  2.   

    您可以使用JSPSmartUpload组件来进行开发。
      

  3.   

    楼上,可以给我发一个jspSmartUpload包吗?
      

  4.   

    刚刚用smartupload方法解决的这个问题 呵呵 http://www.programsalon.com/download.asp?type_id=25&pos=1420