日期:2014-05-17  浏览次数:20688 次

请教jsp中文乱码问题
jsp部分:
contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

html部分:
<!doctype html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

过滤器:
request.setCharacterEncoding("utf-8"); 
response.setContentType("text/html;charset=utf-8");
chain.doFilter(request, response);

感觉该有的都有了啊。

服务器:centOS 服务器编码:en_us.utf-8

在windows上测试没有问题,但布署到远程centOS上后,发现网页里静态的中文显示正常,凡是out.print输出内容,中文全部乱码,请问是怎么回事呢?

------解决方案--------------------
中文后=new String(中文前.getBytes("iso8859-1"),"utf-8");
------解决方案--------------------
你的页面设置成了UTF-8的编码,但你从request里面拿到的数据不一定啊!
------解决方案--------------------
可以试试
引用:
中文后=new String(中文前.getBytes("iso8859-1"),"utf-8");

------解决方案--------------------
response.setCharacterEncoding("utf-8"); 
------解决方案--------------------
楼上正解,在语句可以写在过滤器里,也可以在JSP文件的page指令之后写。还有,在JSP文件中添加了<meta http-equiv="Content-Type" content="text/html; charset=utf-8">,则contentType="text/html; charset=utf-8"可以省略了。
------解决方案--------------------
不管你怎么写,tomcat默认都给你的request用的iso-8895-1编码(除非你配置了tomcat的编码,其实就算配置了也只是对get请求起作用,post照样要自己转码)

out.print之前必须转码,具体看一楼

------解决方案--------------------
tomcat中设置编码为utf-8。
如果还不行,你加入日志,看看到底哪个环节出问题。
------解决方案--------------------
request.setCharacterEncoding("utf-8"); 
response.setContentType("text/html;charset=utf-8");
out对象的获取要在上两行代码后面写,试下行不
------解决方案--------------------
引用:
tomcat中设置编码为utf-8。
如果还不行,你加入日志,看看到底哪个环节出问题。

正解.