处理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;
}
}
中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;
}
}
相关文章推荐
- action接收到来自jsp页面的请求时出现中文乱码问题处理方法
- 关于jsp页面中中文乱码问题的解决方法
- jsp页面显示及数据库中文乱码问题解决方法
- JSP页面中超链接传递中文参数出现乱码问题解决方法
- Ajax GET和POST方法传参导致JSP中文乱码 字符集问题
- JSP页面UTF-8格式中文字符串乱码问题解决方法
- jsp中使用传参时出现中文乱码问题的解决方法
- 解决PHP中json_encode函数处理中文乱码的问题 两种方法
- Java Web中使用JSPSmartUpload控件实现文件的上传和下载(解决了中文乱码问题)(JSP页面采用GBK编码)
- jsp get传参中文乱码问题解决方法
- Jsp之我遇到过的中文乱码问题和解决方法
- 利用Filter类处理jsp页面中的中文乱码问题
- Java Web中使用JSPSmartUpload控件实现文件的上传和下载(解决了中文乱码问题)(JSP页面采用GBK编码)
- 解决jsp页面之间,jsp和后台之间传参中文乱码问题
- linux+tomcat struts 2 Jsp页面传值中文乱码问题解决方法
- MyEclipse 创建jsp页面出现中文乱码问题解决方法
- JSP页面中超链接传递中文参数出现乱码问题解决方法
- 关于jsp页面 title中文乱码问题的解决方法
- JSP中获取HTML中的中文内容是乱码的解决方法---开发中遇到的问题