WEB阶段中文乱码解决方式总结:

来源:互联网 发布:在淘宝上如何做代理 编辑:程序博客网 时间:2024/05/22 01:44
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")
0 0
原创粉丝点击