首页 > 代码库 > 解决web中的乱码

解决web中的乱码

统一使用utf-8进行编码
数据库的编码格式也是utf-8

对于页面post传过来的不会出现乱码

对于页面get 传过来值解决乱码
方法一:在业务层:userName = new String(userName.getBytes("iso-8859-1"),"utf-8");
方法二:
先在jsp页面中进行:
userName = encodeURL(userName,"UTF-8");
userName = encodeURL(userName,"UTF-8");两次按照utf-8进行编码相当于URLDecoder.encode(userName,"UTF-8");
然后再业务层进行:userName = URLDecoder.decode(userName,"UTF-8");
方法三:万能处理乱码
userName = URLDecoder.encode(userName,"UTF-8");
userName = URLDecoder.decode(userName,"UTF-8");

解决web中的乱码