NutzCN Logo
问答 如何自定义中文过滤器?
发布于 2707天前 作者 qq_6c186ef5 1839 次浏览 复制 上一个帖子 下一个帖子
标签:

如何自定义中文过滤器?

18 回复

啥是中文过滤器?

做编码转换的呀!

因为中文乱码?所以想设置一下req的编码?

我在tomcat的server.xml中设置了编码为utf-8,ajax post提交,在action中设置为@Encoding(input = "utf-8", output = "utf-8"),jsp也是utf-8,提交后,进入数据库还是"????"这样的值,数据库创建的时候也是utf-8

启动日志里面打印的容器编码是什么?

启动日志里面打印的是中文.没有乱码

在此之前是没问题的,切换了一台服务器后,装的是tomcat8,就出现乱码了,

不是指打印的中文,是日志里面打印的编码信息

http://nutzam.com/core/basic/encoding.html

类似下面这样:

21:22:23.237 DEBUG (NutLoading.java:61) load -  - Default Charset : UTF-8

默认是GBK,但我的确是改成UTF-8了

2017-07-25 11:08:14,693 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:55) INFO  - Nutz Version : 1.r.60 
2017-07-25 11:08:14,693 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:56) INFO  - Nutz.Mvc[nutz] is initializing ...
2017-07-25 11:08:14,693 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:60) DEBUG - Web Container Information:
2017-07-25 11:08:14,693 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:61) DEBUG -  - Default Charset : GBK
2017-07-25 11:08:14,693 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:62) DEBUG -  - Current . path  : D:\Program Files\services\Apache\tomcat\tomcat8\.
2017-07-25 11:08:14,693 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:63) DEBUG -  - Java Version    : 1.8.0_131
2017-07-25 11:08:14,693 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:64) DEBUG -  - File separator  : \
2017-07-25 11:08:14,693 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:65) DEBUG -  - Timezone        : Asia/Shanghai
2017-07-25 11:08:14,693 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:66) DEBUG -  - OS              : Windows Server 2008 R2 amd64
2017-07-25 11:08:14,693 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:67) DEBUG -  - ServerInfo      : Apache Tomcat/8.5.16
2017-07-25 11:08:14,693 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:68) DEBUG -  - Servlet API     : 3.1

那就是没改对嘛

我设置的就是utf-8,难道区分大小写,这不应该呀

<Connector port="8000" protocol="HTTP/1.1"
               connectionTimeout="20000"
               redirectPort="8443" URIEncoding="utf-8"/>

仔细看文档,不单单改serve.xml的,还要加jvm参数

设置了之后还是???,这是什么情况啊,日志打印出来是utf-8了,进到数据库还是问号

2017-07-25 11:33:08,758 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:55) INFO  - Nutz Version : 1.r.60 
2017-07-25 11:33:08,758 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:56) INFO  - Nutz.Mvc[nutz] is initializing ...
2017-07-25 11:33:08,758 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:60) DEBUG - Web Container Information:
2017-07-25 11:33:08,758 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:61) DEBUG -  - Default Charset : UTF-8
2017-07-25 11:33:08,758 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:62) DEBUG -  - Current . path  : D:\Program Files\services\Apache\tomcat\tomcat8\.
2017-07-25 11:33:08,758 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:63) DEBUG -  - Java Version    : 1.8.0_131
2017-07-25 11:33:08,758 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:64) DEBUG -  - File separator  : \
2017-07-25 11:33:08,758 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:65) DEBUG -  - Timezone        : Asia/Shanghai
2017-07-25 11:33:08,758 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:66) DEBUG -  - OS              : Windows Server 2008 R2 amd64
2017-07-25 11:33:08,758 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:67) DEBUG -  - ServerInfo      : Apache Tomcat/8.5.16
2017-07-25 11:33:08,773 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:68) DEBUG -  - Servlet API     : 3.1
2017-07-25 11:33:08,773 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:73) DEBUG -  - ContextPath     : /risun-back
2017-07-25 11:33:08,773 org.nutz.mvc.impl.NutLoading.load(NutLoading.java:74) DEBUG -  - context.tempdir : D:\Program Files\services\Apache

mysql的数据库编码也会打印的,贴一下

也是utf-8,还有个问题哈,就是在打印出的失去了执行insert是执行成功日志打印的是中文,到数据库是???

2017-07-25 11:33:10,692 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_client=latin1
2017-07-25 11:33:10,692 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_connection=latin1
2017-07-25 11:33:10,692 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_database=utf8
2017-07-25 11:33:10,692 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_filesystem=binary
2017-07-25 11:33:10,692 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_results=
2017-07-25 11:33:10,692 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_server=latin1
2017-07-25 11:33:10,692 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_set_system=utf8
2017-07-25 11:33:10,692 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:212) DEBUG - Mysql : character_sets_dir=C:\Program Files (x86)\MySQL\MySQL Server 5.1\share\charsets\
2017-07-25 11:33:10,692 org.nutz.dao.impl.jdbc.mysql.MysqlJdbcExpert.checkDataSource(MysqlJdbcExpert.java:219) DEBUG - Mysql : binlog_format=STATEMENT

insert的log

2017-07-25 11:34:47,989 org.nutz.ioc.impl.NutIoc.get(NutIoc.java:151) DEBUG - Get 'newsAction'<class com.risun.news.module.news.NewsAction>

2017-07-25 11:34:48,005 com.mchange.v2.resourcepool.BasicResourcePool.trace(BasicResourcePool.java:1644) DEBUG - trace com.mchange.v2.resourcepool.BasicResourcePool@16b238d [managed: 3, unused: 2, excluded: 0] (e.g. com.mchange.v2.c3p0.impl.NewPooledConnection@9bd792a)
2017-07-25 11:34:48,005 org.nutz.dao.impl.sql.run.NutDaoExecutor.printSQL(NutDaoExecutor.java:388) DEBUG - INSERT INTO sm_news(codes,newCodes,newsTitle,newsContents,newTypeId,newType,publishDate,addUser,newsFrom,scannerTimes,dutyEditor,newsPage,search,newsImg,prsiseTimes,playTourMoney,transpondTimes,stickNum,sort,istopLine) VALUES(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?) 
    |                1 | 2 |     3 |      4 |  5 |    6 |                   7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |  16 | 17 | 18 | 19 | 20 |
    |------------------|--|-------|--------|----|------|---------------------|---|---|---|---|---|---|--|---|-----|---|---|---|---|
    | 0h5j4U4S5f6Y2z7a |  | v大杀四方 | 地方郭德纲人 | 80 | 精彩图览 | 2017-07-25 11:34:48 | 0 | 2 | 0 | 2 | 2 | 2 |  | 0 | 1.0 | 0 | 0 | 2 | 0 |
  For example:> "INSERT INTO sm_news(codes,newCodes,newsTitle,newsContents,newTypeId,newType,publishDate,addUser,newsFrom,scannerTimes,dutyEditor,newsPage,search,newsImg,prsiseTimes,playTourMoney,transpondTimes,stickNum,sort,istopLine) VALUES('0h5j4U4S5f6Y2z7a','','v大杀四方','地方郭德纲人',80,'精彩图览','2017-07-25 11:34:48',0,'2',0,'2','2','2','',0,1.0,0,0,2,0) "

客户端并非utf8,按文档上那样,改jdbcUrl

ps,mysql 5.6等新版mysql,安装的时候就可以设置编码,utf8保平安

添加回复
请先登陆
回到顶部