乱码产生的原因:发送的编码格式和接受的编码格式不一致。
一.接收的数据是乱码
1)get方式
1.在tomcat下conf文件夹service.xml的<Connector>元素中添加 useBodyEncodingForURI="true"或 者URIEncoding="utf-8"(建议使用前者,较灵活)
2.request.setCharacterEncoding("utf-8");
2)post方式
request.setCharacterEncoding("utf-8");
二.响应的数据是乱码
response.setContentType("text/html;charset=utf-8");
一.接收的数据是乱码
1)get方式
1.在tomcat下conf文件夹service.xml的<Connector>元素中添加 useBodyEncodingForURI="true"或 者URIEncoding="utf-8"(建议使用前者,较灵活)
2.request.setCharacterEncoding("utf-8");
2)post方式
request.setCharacterEncoding("utf-8");
二.响应的数据是乱码
response.setContentType("text/html;charset=utf-8");