本文以最常见的JSP+MySQL+Tomcat+Apache乱码解决为例,望能为你的环境配置起到抛砖引玉之效!
乱码问题已历来已久,在开源环境下,乱码问题更是令程序员措手不及。本人在Unix(Freebsd)下的一次乱码经历可谓经典,故撰以此文以滋效尤!
我将本次所遇乱码归为三类:
1.页面字符乱码
2.记录显示乱码
3.request传递乱码
以下将对上述三类乱码进行解析:
一.页面字符乱码:
1.大小写不一致:
org.apache.jasper.JasperException: /top.jsp(1,1) Page directive: illegal to have multiple occurrences of contentType with different values (old: text/html;charset=gb2312, new: text/html;charset=GB2312)
2.间隔不一致:
org.apache.jasper.JasperException: /top.jsp(1,1) Page directive: illegal to have multiple occurrences of contentType with different values (old: text/html; charset=GB2312, new: text/html;charset=GB2312)
*解决方案:
首先,在Apache中增加AddDefaultCharset GB2312或AddDefaultCharset GBK
其次,统一使用页面编码定义,如:,OK,果然是乱。那么,现在有两种解决方法。
*解决方案:
1.加上这条语句:request.setCharacterEncoding("gbk");
TAG标签 : 解决 乱码 import null encoding request if 文件 true
个人空间
