JAVA修正乱码

来源:百度知道 编辑:UC知道 时间:2024/06/28 10:25:12
public static String toChinese(String strvalue){
try{
if(strvalue==null){
return"";
}else{
strvalue=new String(strvalue.getBytes("ISO8859_1"),"GBK").trim();
return strvalue;
}
}catch(Exception e){
return"";
}
}
这是一段修正乱码的方法,假如我的WEB页面中有乱码显示的问题,我要如何调用这段代码啊 ?

这个简单。
你显示的乱码作为参数传入toChinese方法中即可。
比如:你登录的时候,要显示用户的用户名和密码。
String uname = request.getParameter("username");//显示乱码
String u_name = toChinese(uname); //这样你就可以正确的中文了

密码也是同理的,就不写了……

现在知道了吗?