上网看了一下才知道jspsmart不支持中文~~~~,晕~~~~要升级它
1.用jad 反编译 得到java文件
这里也可能会遇到难题~~~
我的机子还装了C#的VS,所以可能反编译时用的是vs的编译器.如果把这样反编译得到的.java文件放在eclipse下是不能编译成.class的,所以要自己一个个地新建一个类,然后复制内容进去~~~~~
![]()
2.添加方法
SmartUpload.java中加入
- //添加转换文件名字符串的方法
- public static String toUtf8String(String s) {
- StringBuffer sb = new StringBuffer();
- for (int i = 0; i < s.length(); i++) {
- char c = s.charAt(i);
- if (c >= 0 && c <= 255) {
- sb.append(c);
- } else {
- byte[] b;
- try {
- b = Character.toString(c).getBytes("utf-8");
- } catch (Exception ex) {
- System.out.println(ex);
- b = new byte[0];
- }
- for (int j = 0; j < b.length; j++) {
- int k = b[j];
- if (k < 0)
- k += 256;
- sb.append("%" + Integer.toHexString(k).toUpperCase());
- }
- }
- }
- return sb.toString();
- }
修改downloadFile方法
- 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)));
- //转换文件名
- else
- if(s2.length() == 0)
- m_response.setHeader("Content-Disposition", m_contentDisposition);
- else
- m_response.setHeader("Content-Disposition", m_contentDisposition + " filename=" + toUtf8String(s2));
- //转换文件名
- while((long)k < l)
- {
- int j = fileinputstream.read(abyte0, 0, i);
- k += j;
- m_response.getOutputStream().write(abyte0, 0, j);
- }
- fileinputstream.close();
- }
这里只是对文件名的字符进行更改.
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();
}
本文介绍了一种解决JSpsmart框架不支持中文的问题的方法,通过添加文件名转换方法并修改下载逻辑,使得文件名在下载时不出现乱码。

被折叠的 条评论
为什么被折叠?



