版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012611878/article/details/80723491 </div>
<link rel="stylesheet" href="https://csdnimg.cn/release/phoenix/template/css/ck_htmledit_views-f57960eb32.css">
<div id="content_views" class="markdown_views">
<!-- flowchart 箭头图标 勿删 -->
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
<path stroke-linecap="round" d="M5,0 0,2.5 5,5z" id="raphael-marker-block" style="-webkit-tap-highlight-color: rgba(0, 0, 0, 0);"></path>
</svg>
<h1 id="工程乱码"><a name="t0"></a>工程乱码</h1>
打开File-Setting, 找到File Encodings这个选项,把encoding设置成你工程的编码即可,一般是UTF-8,如下图(红框的地方),然后重新rebuild一下,基本就行了
执行main函数时,控制台乱码
同样是打开setting,找到 Build,Execution,Deployment > Compiler > Java Compiler, 设置 Additional command line parameters选项为 -encoding utf-8,然后rebuild下,重新运行
运行tomcat时,控制台乱码
1)打开Run/Debug Configuration,选择你的tomcat
2)然后在 Server > VM options 设置为 -Dfile.encoding=UTF-8 ,重启tomcat
其他乱码
1)数据库数据是否乱码
查看数据库编码类型
show variables like ‘character%’
- 1
character_set_client utf8
character_set_connection utf8
character_set_database utf8
character_set_filesystem binary
character_set_results utf8
character_set_server utf8
character_set_system utf8
character_sets_dir /aebiz/soft/mysql/share/charsets/
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
2)jsp乱码
查看代码中是否添加下面代码
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8" %>
- 1
3)request和response
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
response.setContentType("text/html;charset=utf-8");
- 1
- 2
- 3
另外java字符串编码也需注意 转发至:https://blog.csdn.net/u012611878/article/details/80723491