您的位置:首页 > Web前端 > JavaScript

处理JSP中文跨页面间传参乱码的问题有两种方法实现方法(每个搞JSP的最常遇到的问题之一) 实例版:)

2007-03-16 12:00 966 查看
处理JSP中文跨页面间传参乱码的问题有两种方法实现方法:(1)代码处理,(2)Tomcat
中server.Xml文档的对Unicode的设定。

下面详细介绍代码处理这种实现方法.
原理:有源页面A与目标页面B,A中先对参转ISO8859_1,到B再还原原先的编码:如
:utf-8,big5,gb2312等等。
实例(简洁版):
跳转前:
String str_value=new String(("北京西大街188号d").getBytes("utf-
8"),"ISO8859-1");
跳转后:
out.println(new String(request.getParameter("address").getBytes("ISO8859
-1"),"utf-8"));
实例(类库版):
提供的java包:调用这两个类中函数中就可以(适用于用设置为utf-8的页面)
同理,可把utf-8这个参数改为你要用的就可以了。
package student;
public class big5toutf {
public big5toutf(){
}
public static String utf_8toISO8859_1(String str)

{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("utf-8");

String temp=new String(temp_t,"ISO8859_1");
return temp;
}catch(Exception e)
{
System.out.println(e);
}
return null;
}
public static String ISO8859_1toutf_8(String str)

{
try
{
String temp_p=str;
byte[] temp_t=temp_p.getBytes("ISO8859_1");
String temp=new String(temp_t,"utf-8");
return temp;
}catch(Exception e)
{
System.out.println(e);
}
return null;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: