1.修改工作空間編碼方式為UTF-8
- window-->properties-->General-->Workspace-->Other-->UTF-8
2.創建的jsp全部修改為UTF-8
- 修改jsp默認編碼方式 window --> preference --> Web --> JSP Files --> Encoding 修改為UTF-8
3.在doGet()/doPost里面加上以下代碼
request.setCharacterEncoding("UTF-8"); response.setContentType("text/html; charset=UTF-8");
4.對於get方式提交到Servlet的數據,中文亂碼處理請參照下面示例
String username = request.getParameter("username"); username = new String(username.getBytes("ISO-8859-1"),"UTF-8");
5.mysql亂碼處理,在原來的URL后面加上?useUnicode=true&characterEncoding=UTF-8
jdbcUrl=jdbc:mysql://localhos:3306/greadManagert?useUnicode=true&characterEncoding=UTF-8
- 如果在xml中識別不了&符號,要使用實體字符"&"加“;”來代替&,即
jdbcUrl=jdbc:mysql://localhos:3306/greadManagert?useUnicode=true&characterEncoding=UTF-8
6.修改tomcat配置文件server.xml,63行,加上URIEncoding="utf-8"
<Connector URIEncoding="utf-8" connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443"/>
7.配置亂碼過濾器
<!-- 亂碼過濾器 --> <filter> <filter-name>encodingFilter</filter-name> <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class> <async-supported>true</async-supported> <init-param> <param-name>encoding</param-name> <param-value>UTF-8</param-value> </init-param> </filter> <filter-mapping> <filter-name>encodingFilter</filter-name> <url-pattern>/*</url-pattern> </filter-mapping>
番外篇:自動提示
- window-->preference-->java-->Editor-->Content Assist-->Auto activation triggers for java,在里面把a--z二十六個字母全輸入進去