很简单:
   直接把你写的jsp的url指向一个WORD文件或TXT文件,默认情况文件为只读.

解决方案 »

  1.   

    可是我已在JSP里把URL指向一个WORD文件或TXT文件,但打开看到的是乱码呀??
      

  2.   

    // Set the browser's mime type
    response.setContentType("application/msword");response.addHeader("Content-disposition", "inline; filename=myword.doc");
      

  3.   

    还是写给你吧
    我曾遇到过。可以这样写
    在JSP里引入,
    这样用jsp:
    String doc_name_new=toDocChinese.URLEncode(doc_name);
    java 类
    import java.io.ByteArrayOutputStream;
    import java.io.IOException;
    import java.io.OutputStreamWriter;
    import java.util.BitSet;
    public class toDocChinese {
     public static String URLEncode(String path) {
            int maxBytesPerChar = 10;
            int caseDiff = ('a' - 'A');
            char[] hexadecimal = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9','A', 'B', 'C', 'D', 'E', 'F'};
            BitSet safeCharacters = new BitSet(256);
            StringBuffer rewrittenPath = new StringBuffer(path.length());
            ByteArrayOutputStream buf = new ByteArrayOutputStream(maxBytesPerChar);
            OutputStreamWriter writer = null;
            try {
                writer = new OutputStreamWriter(buf, "UTF8");
            } catch (Exception e) {
                e.printStackTrace();
                writer = new OutputStreamWriter(buf);
            }        for (int i = 0; i < path.length(); i++) {
                int c = (int) path.charAt(i);
                if (safeCharacters.get(c)) {
                    rewrittenPath.append((char)c);
                } else {
                    try {
                        writer.write(c);
                        writer.flush();
                    } catch(IOException e) {
                        buf.reset();
                        continue;
                    }
                    byte[] ba = buf.toByteArray();
                    for (int j = 0; j < ba.length; j++) {
                        byte toEncode = ba[j];
                        rewrittenPath.append('%');
                        int low = (int) (toEncode & 0x0f);
                        int high = (int) ((toEncode & 0xf0) >> 4);
                        rewrittenPath.append(hexadecimal[high]);
                        rewrittenPath.append(hexadecimal[low]);
                    }
                    buf.reset();
                }
            }
            return rewrittenPath.toString();
        }
    }