在javaweb开发中很经常的碰到一个问题,那就是中文乱码:
解决方案有以下几点:
1.配置server.xml,解决从页面传值到后台时出现乱码:
<Connector port="8080" maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
enableLookups="false" redirectPort="8443" acceptCount="100"
connectionTimeout="20000" disableUploadTimeout="true" URIEncoding='UTF-8' />
2.配置jdbc,解决从后台存储数据到数据库
jdbc:mysql://localhost:3306/cmr?useUnicode=true&characterEncoding=utf-8
3.设置response.setCharacterEncoding("utf-8"),解决从后台传值到页面时出现乱码;;
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setCharacterEncoding("utf-8");
response.setCharacterEncoding("utf-8");
......
}
未完待续