ie打开的话全都是乱码。谢谢各位大虾

解决方案 »

  1.   

    import java.io.*;import java.util.*;
    import javax.servlet.*;
    import javax.servlet.http.*;public class  Download extends HttpServlet
    {
        public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
        {
            try
            {
             new String(name.getBytes("GBK"), "ISO8859_1")
                //这里你可以做些其他的事情
                response.setContentType("application/octet-stream");
                response.setHeader("Content-Disposition", "attachment; filename=\"你要在保存窗口中显示的保存文件名\"");//对于中文要使用类似new String(name.getBytes("GBK"), "ISO8859_1")的写法
                    
                BufferedInputStream in = null;
                ServletOutputStream out = null;
                FileInputStream stream = null;
                try {
                    out = response.getOutputStream();
                    stream = new FileInputStream(file);                int bytesRead = 0;
                    final int length = 8192;
                    byte[] buffer = new byte[length];
                    while ((bytesRead = stream.read(buffer, 0, length)) != -1) {
                        // write at server side
                        out.write(buffer, 0, bytesRead);
                    }
                } catch (IOException e) {
                    throw new BPDBusiException(
                         ResourceConst.SCORECARD_ERR_DOWNLOADATTACHMENT_DOWNLOAD);
                } finally {
                    if (in != null) {
                        in.close();
                    }
                    if (out != null) {
                        out.close();
                    }
                }
            }
            catch (Exception e)
            {
                System.out.println(e);
            }
        }
        public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException
        {
            doGet(request, response);
        }
    }
      

  2.   

    response.setContentType("application/octet-stream");
                response.setHeader("Content-Disposition", "attachment; filename=\"你要在保存窗口中显示的保存文件名\"");//对于中文要使用类似new String(name.getBytes("GBK"), "ISO8859_1")的写法能够让你进行下载。
    中间那段,可以让你传输二进制文件。