jspsmart 下载文件不支持中文 升级使其另存为时显示中文,但打开时还是乱码(已修改正常)

上网看了一下才知道jspsmart不支持中文~~~~,晕~~~~要升级它

 

1.用jad 反编译 得到java文件

     这里也可能会遇到难题~~~

    我的机子还装了C#的VS,所以可能反编译时用的是vs的编译器.如果把这样反编译得到的.java文件放在eclipse下是不能编译成.class的,所以要自己一个个地新建一个类,然后复制内容进去~~~~~

 

 

2.添加方法

SmartUpload.java中加入

 

  1. //添加转换文件名字符串的方法
  2.     public static String toUtf8String(String s) {
  3.         StringBuffer sb = new StringBuffer();
  4.         for (int i = 0; i < s.length(); i++) {
  5.             char c = s.charAt(i);
  6.             if (c >= 0 && c <= 255) {
  7.                 sb.append(c);
  8.             } else {
  9.                 byte[] b;
  10.                 try {
  11.                     b = Character.toString(c).getBytes("utf-8");
  12.                 } catch (Exception ex) {
  13.                     System.out.println(ex);
  14.                     b = new byte[0];
  15.                 }
  16.                 for (int j = 0; j < b.length; j++) {
  17.                     int k = b[j];
  18.                     if (k < 0)
  19.                         k += 256;
  20.                     sb.append("%" + Integer.toHexString(k).toUpperCase());
  21.                 }
  22.             }
  23.         }
  24.         return sb.toString();
  25.     }

修改downloadFile方法

 

  1. public void downloadFile(String s, String s1, String s2, int i)
  2.         throws ServletException, IOException, SmartUploadException
  3.     {
  4.         if(s == null)
  5.             throw new IllegalArgumentException("File '" + s + "' not found (1040).");
  6.         if(s.equals(""))
  7.             throw new IllegalArgumentException("File '" + s + "' not found (1040).");
  8.         if(!isVirtual(s) && m_denyPhysicalPath)
  9.             throw new SecurityException("Physical path is denied (1035).");
  10.         if(isVirtual(s))
  11.             s = m_application.getRealPath(s);
  12.         java.io.File file = new java.io.File(s);
  13.         FileInputStream fileinputstream = new FileInputStream(file);
  14.         long l = file.length();
  15.         boolean flag = false;
  16.         int k = 0;
  17.         byte abyte0[] = new byte[i];
  18.         if(s1 == null)
  19.             m_response.setContentType("application/x-msdownload");
  20.         else
  21.         if(s1.length() == 0)
  22.             m_response.setContentType("application/x-msdownload");
  23.         else
  24.             m_response.setContentType(s1);
  25.         m_response.setContentLength((int)l);
  26.         m_contentDisposition = m_contentDisposition != null ? m_contentDisposition : "attachment;";
  27.         if(s2 == null)
  28.             m_response.setHeader("Content-Disposition", m_contentDisposition + " filename=" + toUtf8String(getFileName(s)));
  29.       //转换文件名
  30.         else
  31.         if(s2.length() == 0)
  32.             m_response.setHeader("Content-Disposition", m_contentDisposition);
  33.         else
  34.             m_response.setHeader("Content-Disposition", m_contentDisposition + " filename=" + toUtf8String(s2));
  35.         //转换文件名
  36.         while((long)k < l) 
  37.         {
  38.             int j = fileinputstream.read(abyte0, 0, i);
  39.             k += j;
  40.             m_response.getOutputStream().write(abyte0, 0, j);
  41.         }
  42.         fileinputstream.close();
  43.     }

这里只是对文件名的字符进行更改.

 

3.用eclipse打包

 

打包时去掉.classpath ; .project前的勾~~~~

 

 

 4.打开后不乱码的修改方法~~~

SmartUpload.java

 

public void downloadFile(String s, String s1, String s2, int i)
        throws ServletException, IOException, SmartUploadException
    {
        if(s == null)
            throw new IllegalArgumentException("File '" + s + "' not found (1040).");
        if(s.equals(""))
            throw new IllegalArgumentException("File '" + s + "' not found (1040).");
        if(!isVirtual(s) && m_denyPhysicalPath)
            throw new SecurityException("Physical path is denied (1035).");
        if(isVirtual(s))
            s = m_application.getRealPath(s);
        java.io.File file = new java.io.File(s);
        FileInputStream fileinputstream = new FileInputStream(file);
        long l = file.length();
        boolean flag = false;
        int k = 0;
        byte abyte0[] = new byte[i];
        if(s1 == null)
            m_response.setContentType("application/x-msdownload");
        else
        if(s1.length() == 0)
            m_response.setContentType("application/x-msdownload");
        else
            m_response.setContentType(s1);
        m_response.setContentLength((int)l);
        m_contentDisposition = m_contentDisposition != null ? m_contentDisposition : "attachment;";
        if(s2 == null)
            //m_response.setHeader("Content-Disposition", m_contentDisposition + " filename=" + toUtf8String(getFileName(s)));
            m_response.setHeader("Content-Disposition", m_contentDisposition + " filename=" + new String(getFileName(s).getBytes("gb2312"),"iso8859-1"));
           
      //转换文件名
        else
        if(s2.length() == 0)
            m_response.setHeader("Content-Disposition", m_contentDisposition);
        else
            //m_response.setHeader("Content-Disposition", m_contentDisposition + " filename=" + toUtf8String(s2));
         m_response.setHeader("Content-Disposition", m_contentDisposition + " filename=" + new String(getFileName(s).getBytes("gb2312"),"iso8859-1"));
        //转换文件名
        while((long)k < l)
        {
            int j = fileinputstream.read(abyte0, 0, i);
            k += j;
            m_response.getOutputStream().write(abyte0, 0, j);
        }
        fileinputstream.close();
    }

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值