加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

aja乱码解决

发布时间:2020-12-16 00:26:33 所属栏目:百科 来源:网络整理
导读:1. 网页页面使用utf-8 meta http-equiv="Content-type" content="text/html; charset=utf-8" 2. ajax默认使用utf-8传输数据,但最好使用post,不要使用get 3. Struts2中使用UTF-8. 3.1 在struts.properties中加上: struts.i18n.encoding=UTF-8 [3.2 使用Filter
1. 网页页面使用utf-8
<meta http-equiv="Content-type" content="text/html; charset=utf-8">

2. ajax默认使用utf-8传输数据,但最好使用post,不要使用get

3. Struts2中使用UTF-8.
3.1 在struts.properties中加上: struts.i18n.encoding=UTF-8
[3.2 使用Filter: 从页面中传输数据到Struts2,需要使用过滤器把数据在交给struts2前转换成utf-8的: http://stevieliu.blogchina.com/stevieliu/6223098.html]
试过不使用3.2照常可以收到中文.

4. 数据库也要使用utf-8,在建表时设置好.
http://imysql.cn/charset_tips

5. hibernate.cf.xml配置文件中与数据库的连接符串也要标明使用的编码为utf-8: <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mlm?useUnicode=true&amp;characterEncoding=UTF-8</property>

6: Tomcat也使用UTF-8
6.1: Tomcat/bin/catalina.bat中开始部分(大概51行处)添加set CATALINA_OPTS=-Dfile.encoding=UTF-8
或CATALINA_OPTS="$CATALINA_OPTS -Dfile.encoding=UTF-8"
6.2: <Connector URIEncoding="utf-8" port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
Eclipse启动Tomcat会修改Tomcat的运行编码环境,从终端启动的又是另一种编码环境,所以Tomcat的配置也要手动修改

7: HttpServletResponse(request)也要设置编码:response.
setCharacterEncoding("UTF-8");

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读