jsp页面字符集问题 编码是utf-8时,页面中文肯定会出现乱码,因为中文编码是gb2312的,如果使用utf-8显示中文,必须把中文转换为unicode码才可以,不能直接写中文,也就是必须转成/u#### 的unicode码 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 用<%@ page contentType="text/html; charset=UTF-8" %>时,中文输入为什么会出现乱码。一般这种情况都应该怎么解决呢 一般情况下是把所有的中文放入资源文件,然后把资源文件统一编为unicode码这样可以达到国际化 看你的代码使用的是jsp吧java里面有个工具native2ascii.exe,就是用来转换unicode码的,就在%JAVAHOME%/bin/下面 Sorry to bother you a lot.我所做的是一个portal项目,有很多页面,和这个工具接合起来用不太好吧。有没有一种什么转换函数可以把他们转换过来。 这个我手头没有,你去google搜一下吧,呵呵,不好意思@_@ 我在网上找了个函数 static public String convertUTF8String2Unicode(String instr)throws IOException {//byte[] strbytes = instr.getBytes();int charindex = instr.length();int actualValue;int inputValue;StringBuffer sbtemp = new StringBuffer();for (int i = 0; i < charindex;) {actualValue = -1;inputValue = instr.charAt(i++);inputValue &= 0xff; if ((inputValue & 0x80) == 0) { actualValue = inputValue; } else if ((inputValue & 0xF8) == 0xF0) { actualValue = (inputValue & 0x1f) << 18; int nextByte = instr.charAt(i++) & 0xff; if ((nextByte & 0xC0) != 0x80) throw new IOException("Invalid UTF-8 format"); actualValue += (nextByte & 0x3F) << 12; nextByte = instr.charAt(i++) & 0xff; if ((nextByte & 0xC0) != 0x80) throw new IOException("Invalid UTF-8 format"); actualValue += (nextByte & 0x3F) << 6; nextByte = instr.charAt(i++) & 0xff; if ((nextByte & 0xC0) != 0x80) throw new IOException("Invalid UTF-8 format"); actualValue += (nextByte & 0x3F); } else if ((inputValue & 0xF0) == 0xE0) { actualValue = (inputValue & 0x1f) << 12; int nextByte = instr.charAt(i++) & 0xff; if ((nextByte & 0xC0) != 0x80) throw new IOException("Invalid UTF-8 format"); actualValue += (nextByte & 0x3F) << 6; nextByte = instr.charAt(i++) & 0xff; if ((nextByte & 0xC0) != 0x80) throw new IOException("Invalid UTF-8 format"); actualValue += (nextByte & 0x3F); } else if ((inputValue & 0xE0) == 0xC0) { actualValue = (inputValue & 0x1f) << 6; int nextByte = instr.charAt(i++) & 0xff; if ((nextByte & 0xC0) != 0x80) throw new IOException("Invalid UTF-8 format"); actualValue += (nextByte & 0x3F); } sbtemp.append((char) actualValue); } return sbtemp.toString(); } javascript如何取数组中时间计算,算出分钟 IE中抛异常玩。 求一JS菜单 js怎么取系统版本啊 如何删除字符串中的空格 对象中setInterval的问题 怎样为表格新增加的行添加事件?在线等待 能用javascript把IE中的打印设置里页眉和页脚清除掉??? 关于子窗体的问题 如何在窗口关闭时执行函数,而刷新窗体时不会执行该函数 关于菜单的简单问题。 刚接触js,请问这段代码什么意思?
我所做的是一个portal项目,有很多页面,和这个工具接合起来用不太好吧。有没有一种什么转换函数可以把他们转换过来。
static public String convertUTF8String2Unicode(String instr)
throws IOException {
//byte[] strbytes = instr.getBytes();
int charindex = instr.length();
int actualValue;
int inputValue;
StringBuffer sbtemp = new StringBuffer();for (int i = 0; i < charindex;) {actualValue = -1;
inputValue = instr.charAt(i++);inputValue &= 0xff; if ((inputValue & 0x80) == 0) {
actualValue = inputValue;
}
else if ((inputValue & 0xF8) == 0xF0) {
actualValue = (inputValue & 0x1f) << 18; int nextByte = instr.charAt(i++) & 0xff;
if ((nextByte & 0xC0) != 0x80)
throw new IOException("Invalid UTF-8 format");
actualValue += (nextByte & 0x3F) << 12; nextByte = instr.charAt(i++) & 0xff;
if ((nextByte & 0xC0) != 0x80)
throw new IOException("Invalid UTF-8 format");
actualValue += (nextByte & 0x3F) << 6; nextByte = instr.charAt(i++) & 0xff;
if ((nextByte & 0xC0) != 0x80)
throw new IOException("Invalid UTF-8 format");
actualValue += (nextByte & 0x3F);
}
else if ((inputValue & 0xF0) == 0xE0) {
actualValue = (inputValue & 0x1f) << 12; int nextByte = instr.charAt(i++) & 0xff;
if ((nextByte & 0xC0) != 0x80)
throw new IOException("Invalid UTF-8 format");
actualValue += (nextByte & 0x3F) << 6; nextByte = instr.charAt(i++) & 0xff;
if ((nextByte & 0xC0) != 0x80)
throw new IOException("Invalid UTF-8 format");
actualValue += (nextByte & 0x3F);
}
else if ((inputValue & 0xE0) == 0xC0) {
actualValue = (inputValue & 0x1f) << 6; int nextByte = instr.charAt(i++) & 0xff;
if ((nextByte & 0xC0) != 0x80)
throw new IOException("Invalid UTF-8 format");
actualValue += (nextByte & 0x3F);
}
sbtemp.append((char) actualValue);
} return sbtemp.toString();
}