Java中文乱码总结
1.html 乱码
1 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
2.jsp 乱码
页面开头加入
<%@ page language="java" import="java.util.*" contentType ="text/html; charset=utf-8" pageEncoding="utf-8"%>
3.xmlHttpRequest 乱码
<%@ page contentType ="text/html;charset=GBK"%>
4.Servlet 乱码
在方法中 加入这两句
request.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
5.中文注释乱码
原因:Eclipse中对Text file encoding的默认编码是GBK
解决:
Eclipse->右击"工程",将Info中的"Text file encoding"中的Other改为UTF-8
MyEclipse ->pro -> Text file encoding ->Other utf-8
Please keep refueling and don't slack off.