jspsmart字符编码的问题

使用jspsmart上传文件很方便,但是如果使用UTF-8编码,会出现乱码。对于使用 UTF-8编码的项目很不方便。GB2312编码格式不会出现乱码。
今天看了一下,只需要修改一个地方就可以解决问题。
首先反编译SmartUpload类,只需要修改一个私有方法,方法修改如下:
[code]private String getDataHeader() {
int i = m_currentIndex;
int j = 0;
for (boolean flag1 = false; !flag1;)
if (m_binArray[m_currentIndex] == 13
&& m_binArray[m_currentIndex + 2] == 13) {
flag1 = true;
j = m_currentIndex - 1;
m_currentIndex = m_currentIndex + 2;
} else {
m_currentIndex++;
}
//修改开始
String s = null;
try {
//修改代码,首先得到响应的字符编码类型,然后对得到的字符串进行编码。
String encode = m_response.getCharacterEncoding();
if(encode.equalsIgnoreCase("UTF-8")) {
s = new String(m_binArray, i, (j - i) + 1, "UTF-8");
} else {
s = new String(m_binArray, i, (j - i) + 1);
}

} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
//修改结束
return s;
}[/code]
修改之后UTF-8,GBK,GB2312都不会乱码。如果有问题,请联系我!谢谢!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值