您的位置:首页 > 运维架构 > Tomcat

解决Tomcat中文乱码问题

2007-08-09 08:15 225 查看
请求->Tomcat(ISO-8859-1,相当于ASCII码)->GBK

方法一(适用于POST方法):
加入以下方法:
<%@ page contentType="text/html;charset=GBK" %>
request.setCharacterEncoding("GBK");

方法二(适用于GET和POST方法):
byte[] b=userName.getBytes("ISO-8859-1"); //得到字节数组
userName=new String(b,"GBK"); //转换成GBK码
或:
如果页面开始指定charset="GBK"则,参数2可以省略
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"));
String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"GBK");
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: