WEB阶段中文乱码解决方式总结:
以设置utf-8为例:
一、设置jsp页面(标红的三处)
<%@ page language="java" contentType="text/html; charset= UTF-8"
pageEncoding=" UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset= UTF-8">
二、post请求:
request.setCharacterEncoding("utf-8");
三、get请求:
单个处理:new String("中文".getBytes("iso-8859-1"),"utf-8")
Tomcat配置处理:修改server.xml下的配置
方法1:URIEncoding="utf-8";
方法2:useBodyEncodingForURI="true"
四、cookie
转码:Cookie cookie=new Cookie("message",URLEncoder.encode("中文","utf-8"))
解码:URLDecoder.decoder("cookie.getValue","utf-8")
以设置utf-8为例:
一、设置jsp页面(标红的三处)
<%@ page language="java" contentType="text/html; charset= UTF-8"
pageEncoding=" UTF-8"%>
<meta http-equiv="Content-Type" content="text/html; charset= UTF-8">
二、post请求:
request.setCharacterEncoding("utf-8");
三、get请求:
单个处理:new String("中文".getBytes("iso-8859-1"),"utf-8")
Tomcat配置处理:修改server.xml下的配置
方法1:URIEncoding="utf-8";
方法2:useBodyEncodingForURI="true"
四、cookie
转码:Cookie cookie=new Cookie("message",URLEncoder.encode("中文","utf-8"))
解码:URLDecoder.decoder("cookie.getValue","utf-8")