我也一直在找这个解决方法,但是没有找到。
如果你知道后,请发一份给我。([email protected])谢谢!
如果你知道后,请发一份给我。([email protected])谢谢!
解决方案 »
- ClassNotFoundException: javax.persistence.Entity 出错
- message No action instance for path /register could be created
- struts如何实现restful样式的url风格?
- 一个不知道怎么办的传值问题!!!!!!!!!!!!!
- 在线等。。tomcat的问题。。急!!!
- 新手提问请多格忙
- 关于jsp中链接地址是中文出现乱码的问题求解
- 为什么tomcat无法启动??
- access怎么控制日期格式???
- 哪儿可以下载Weblogic,给个网站吧大侠们
- 将字符串转为double型的?
- Lomboz那儿有下?
整个网站全部采用了utf-8,从数据库到bean,到前台的jsp,但有个问题没解决,就是浏览器上传递中文我一直找不到办法解决。
str1 = new String(str.getBytes("UTF-8"),gb2312);
轉成繁體:
str1 = new String(str.getBytes("UTF-8"),big5);
……
如此
public static String toGbkString(String s) {
String temp = new String(s.getBytes("utf-8"),gb2312);
return temp;
}显示的错误是“无法解析gb2312”,String的构造函数里面有这种方法吗?
对了,我的JDK是1.4.1
我现在需要的是怎么把%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C转化为中文
把“%E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C”转化为中文
byte[] b = new byte[3];
int temp;
int index;
try {
while (s.length() != 0) {
index = s.indexOf("%");
if (index == -1)
return sb.append(s).toString();
if (index != 0) {
sb.append(s.substring(0, index));
}
if (index + 9 <= s.length()) {
temp =
Integer.parseInt(s.substring(index + 1, index + 3), 16)
- 256;
b[0] = Byte.parseByte(String.valueOf(temp));
temp =
Integer.parseInt(s.substring(index + 4, index + 6), 16)
- 256;
b[1] = Byte.parseByte(String.valueOf(temp));
temp =
Integer.parseInt(s.substring(index + 7, index + 9), 16)
- 256;
b[2] = Byte.parseByte(String.valueOf(temp)); sb.append(new String(b, "utf-8"));
index += 9;
s = s.substring(index);
} else {
System.out.println("数据格式错误");
return null;
}
}
} catch (UnsupportedEncodingException ue) {
System.out.print("can't convert to gb2312 : " + ue.getMessage());
} catch (NumberFormatException ne) {
System.out.print("can't convert to gb2312 : " + ne.getMessage());
}
return sb.toString();
}
temp = new String(temp.getBytes("utf-8"), "gb2312");
System.out.print(temp);显示为乱码,更不用说当temp = %E4%BD%A0%E5%A5%BD%EF%BC%8C%E4%B8%96%E7%95%8C 的情况了,都是乱码
<%
'将UTF-8编码汉字转换为GB2312码,兼容英文和数字
function UTF2GB(UTFStr)
for Dig=1 to len(UTFStr)
if mid(UTFStr,Dig,1)="%" then
if len(UTFStr) >= Dig+8 then
GBStr=GBStr & ConvChinese(mid(UTFStr,Dig,9))
Dig=Dig+8
else
GBStr=GBStr & mid(UTFStr,Dig,1)
end if
else
GBStr=GBStr & mid(UTFStr,Dig,1)
end if
next
UTF2GB=GBStr
end functionfunction ConvChinese(x)
A=split(mid(x,2),"%")
i=0
j=0
for i=0 to ubound(A)
A(i)=c16to2(A(i))
next
for i=0 to ubound(A)-1
DigS=instr(A(i),"0")
Unicode=""
for j=1 to DigS-1
if j=1 then
A(i)=right(A(i),len(A(i))-DigS)
Unicode=Unicode & A(i)
else
i=i+1
A(i)=right(A(i),len(A(i))-2)
Unicode=Unicode & A(i)
end if
next
if len(c2to16(Unicode))=4 then
ConvChinese=ConvChinese & chrw(int("&H" & c2to16(Unicode)))
else
ConvChinese=ConvChinese & chr(int("&H" & c2to16(Unicode)))
end if
next
end functionfunction c2to16(x)
i=1
for i=1 to len(x) step 4
c2to16=c2to16 & hex(c2to10(mid(x,i,4)))
next
end function
function c2to10(x)
c2to10=0
if x="0" then exit function
i=0
for i= 0 to len(x) -1
if mid(x,len(x)-i,1)="1" then c2to10=c2to10+2^(i)
next
end functionfunction c16to2(x)
i=0
for i=1 to len(trim(x))
tempstr= c10to2(cint(int("&h" & mid(x,i,1))))
do while len(tempstr)<4
tempstr="0" & tempstr
loop
c16to2=c16to2 & tempstr
next
end functionfunction c10to2(x)
mysign=sgn(x)
x=abs(x)
DigS=1
do
if x<2^DigS then
exit do
else
DigS=DigS+1
end if
loop
tempnum=x
i=0
for i=DigS to 1 step-1
if tempnum>=2^(i-1) then
tempnum=tempnum-2^(i-1)
c10to2=c10to2 & "1"
else
c10to2=c10to2 & "0"
end if
next
if mysign=-1 then c10to2="-" & c10to2
end function
%>
方法名称:gb2utf
参数:String gbStr - GB2312编码字串
返回值类型:String
说明:转码,从GB2312转到UTF8
*****************************/
public String gb2utf(String gbStr)
{
byte[] tempStr;
String utfStr=new String("");
try {
tempStr=gbStr.getBytes("ISO8859-1");
utfStr = new String(tempStr,"GBK");
}
catch (UnsupportedEncodingException uee){
System.out.println("Exception: "+uee);
}
return utfStr;
} /*****************************
方法名称:utf2gb
参数:String utfStr - GB2312编码字串
返回值类型:String
说明:转码,从UTF8转到GB2312
*****************************/
public String utf2gb(String utfStr)
{
byte[] tempStr;
String gbStr=new String("");
try {
tempStr=utfStr.getBytes("GBK");
gbStr = new String(tempStr,"ISO8859-1");
}
catch (UnsupportedEncodingException uee){
System.out.println("Exception: "+uee);
}
return gbStr;
}