注册 登录
编程论坛 J2EE论坛

jsp怎么处理表单里得到的乱码?

天上的星 发布于 2010-01-05 15:55, 1116 次点击
我从表单里获得的字母和数字都能正确显示,汉字却全是乱码!
5 回复
#2
lampeter1232010-01-05 16:15
这个方法很有用

jsp中文乱码解决方法request.setCharacterEncoding("gb2312");

1-设置jsp页面<%@ page contentType="text/html; charset=gb2312" %>

2-表单提交后接收字符使用request.setCharacterEncoding("gb2312"); 或者使用servelet过滤器的方法。

mysql中文乱码解决方法

1-使用mysql5.0时在设置向导中的“please select the default character set” 选择“manual selected default character set/collaction”这项,在字符集 中选择使用gb2312字符集!

2-在jsp中进行数据库连接时使用的连接字符串 "jdbc:mysql://localhost/database?useUnicode=true&characterEncoding=gb2312"

#3
流星雨2010-01-06 10:59
最好的办法改成国际码。
写这么一个类。你有多少乱码都给你解决了。
public class Messages {
    private static final String BUNDLE_NAME = "iii.messages"; //这里是你放国际码的文件路径
    private static final ResourceBundle RESOURCE_BUNDLE = ResourceBundle
            .getBundle(BUNDLE_NAME);

    private Messages() {
    }
    //Locale.getDefault()
    public static String getString(String key) {
        try {
            return RESOURCE_BUNDLE.getString(key);
        } catch (MissingResourceException e) {
            return '!' + key + '!';
        }
    }
}
#4
w3970907702010-01-23 18:34
在处理页面添加<%request.setCharacterEncoding("gb2312");%>
#5
cddengineer2010-01-25 18:02
<%@ page contentType="text/html; charset=UTF-8" %>
#6
Bosen2010-03-15 10:50
你要将你的字符转换成byte然后在转换成Srtirng这样就不会出现乱吗了
1