myeclipse 中UTF-8设置
Window选项下---preferences选项;
打开preferences->General->workspace,设置UTF-8;
同样是preferences->MyEclipse->Files and Editors ->CSS、HTML、JSP、JavaScript、XML设置为ISO 10646/Unicode(UTF-8)。
如果没有配置过上述的设置就创建项目出现乱码情况的,点击项目名,右键找到Properties,检查Text file encoding是否为UTF-8;
类和页面同上,右键找到Properties,检查Text file encoding是否为UTF-8;
Web.xml 中的字符集拦截器设置
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
先检查是否设置,没有请加上,如果有请把它放到最上面(亲身经历,找了好久才发现 T_T)
tomcat 字符集设置
//服务器安装路径下conf文件夹里的server.xml文件
tomcat/conf/server.xml文件
将相关语句改为:
<Connector port="8008" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" URIEncoding="UTF-8"/>
之前的语句没有URIEncoding="UTF-8"这一句
mysql字符集设置
第一种是修改mysql的my.ini文件中的字符集键值
default-character-set = utf8
character_set_server = utf8
修改完后,重启mysql的服务
还有一种,就是使用mysql的命令
SET character_set_client = utf8 ;
SET character_set_connection = utf8 ;
连接数据库设置字符
jdbc.url=jdbc:mysql://localhost:3306/数据库?useUnicode=true&characterEncoding=UTF-8
方法中设置字符
HttpServletResponse res = ServletActionContext.getResponse();
HttpServletRequest request = ServletActionContext.getRequest();
res.setCharacterEncoding("utf-8");
res.setContentType("text/html;charset=utf-8");
request.setCharacterEncoding("utf-8");
注解设置字符
在SSM框架中的注解里加一句话:
produces = "text/html;charset=UTF-8"
例如:@RequestMapping(value="/selectMallByTitle",produces = "text/html;charset=UTF-8")
转载于:https://blog.51cto.com/12266096/2382506