Javaweb项目中提交表单上传到服务器的编码是乱码,如下图所示:
乱码问题,无非就是编解码不一致,常见问题有如下几种,应用服务器编码,数据库编码,连接数据库指定的URL:
1、tomcat字符编码格式
关于URIEncoding
This specifies the character encoding used to decode the URI bytes, after %xx decoding the URL. If not specified, ISO-8859-1 will be used.
译文:这指定了用于解码URI字节的字符编码。如果没有指定,将使用ISO-8859-1。
如:
<Server port="8005" shutdown="SHUTDOWN">
<!-- 其他配置 -->
<Service name="Catalina">
<Connector port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8" />
<!-- 其他配置 -->
</Service>
</Server>
2、mysql数据库编码
检查数据库编码是否和应用编码一致
3.应用服务器连接tomcat的URL没有加编码指定或者编码指定格式不正确