你是用什么写的JSP Or Servlet?
如果你是用JSP,那么你么注意,在<%@%>这些所有的标记之间是不能存在回车的,
你么把它们都删掉

解决方案 »

  1.   

    我这个下了一个exe,可以运行,下了一个txt,里面的gb2312码没变,清清楚楚啊。package test;import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;public class Servlet1 extends HttpServlet {
      private static final String CONTENT_TYPE = "text/html; charset=GBK";
      //Initialize global variables
      public void init() throws ServletException {
      }
      //Process the HTTP Get request
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          this.getFile("D:\\文档1234567890.txt", request, response);
      }  public static void getFile(String filename, HttpServletRequest request, HttpServletResponse response) throws IOException
      {
        long totalsize = 0;
        File f = new File(filename);
        long filelength = f.length();
        byte[] b = new byte[(int)filelength];
        FileInputStream fin = new FileInputStream(f);
        DataInputStream in = new DataInputStream(fin);
        in.read(b);
        response.setContentType("application/exe");
        filename = filename.substring(filename.lastIndexOf("\\") + 1, filename.length());
        response.setHeader("Content-Disposition", "attachment;filename="+filename);
        String filesize = "" + filelength;
        response.setHeader("Content-Length", filesize);
        ServletOutputStream servletOut = response.getOutputStream();
        servletOut.write(b);
        servletOut.flush();
        servletOut.close();
      }  //Clean up resources
      public void destroy() {
      }
    }
      

  2.   

    To ChDw(米),不是你说的那些问题,呵呵,不过还是谢谢了!
    我用的是jbuilder,我测试用的jsp2.jsp文件代码如下:
    <%@ page import="test.file" contentType="text/html; charset=gb2312"%>
    <%
      String strfile = "D:\\123.txt";
      file.getfile1(strfile, request, response);
    %>
    123.txt存在服务器的d盘上,浏览jsp2.jsp下载文件后用winHex比较源文件和下载后的文件,发现首尾个多了一个Hex(0A),以至出现乱码,翻遍所有的书和jbuilder自带的帮助均没找到说法,还请各位大虾赐教!!!