博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
EL表达式取值中文再发送请求时会乱码
阅读量:6717 次
发布时间:2019-06-25

本文共 4310 字,大约阅读时间需要 14 分钟。

 问题描述:

在网站底部进行评论,点击提交按钮时,后台tomcat报错,通过火狐浏览器的firebug看到发送的POST请求体中,有一个title参数是乱码,

导致该字段超长违反了数据库字段的长度约束:

这个title字段的应该是文章的标题(中文):

tomcat报错信息:

2017-06-15 16:15:50,448 DEBUG [modules.cms.dao.CommentDao.findList] - <==      Total: 1============乱码部分内容===========中央第åä¸å·¡è§ ç»åé西çå§åé¦å·¡ è§&ldquo;å头ç&rdquo;æåµ2017-06-15 16:17:12,911 DEBUG [modules.cms.dao.CommentDao.get] - ==>  Preparing: SELECT a.id AS "id", a.category_id AS "category.id", a.content_id AS "contentId", a.title AS "title", a.content AS "content", a.name AS "name", a.ip AS "ip", a.create_date AS "createDate", a.audit_user_id AS "auditUser.id", a.audit_date AS "auditDate", a.del_flag AS "delFlag" FROM cms_comment a WHERE a.id = ? 2017-06-15 16:17:12,912 DEBUG [modules.cms.dao.CommentDao.get] - ==> Parameters: 0(String)2017-06-15 16:17:12,913 DEBUG [modules.cms.dao.CommentDao.get] - <==      Total: 02017-06-15 16:17:12,917 DEBUG [modules.cms.dao.CommentDao.insert] - ==>  Preparing: INSERT INTO cms_comment( id, category_id, content_id, title, content, name, ip, create_date, audit_user_id, audit_date, del_flag ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ) 2017-06-15 16:17:12,924 DEBUG [modules.cms.dao.CommentDao.insert] - ==> Parameters:   dd82abcfbd4d4176b8400dce7b8a0dd0(String),   106c3f5a9d354d69946304ba1003e85e(String),   9948c62c9ab4491daadccfe23032534b(String),   中央第åä¸å·¡è§   ç»åé西çå§åé¦å·   ¡è§&ldquo;å头ç&rdquo;æåµ(String),   测试评论(String),   小李(String),   0:0:0:0:0:0:0:1(String),   2017-06-15 16:17:12.916(Timestamp),   null,   null,   2(String) 2017-06-15 16:17:13,035 ERROR [500.jsp] - ### Error updating database.  Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'title' at row 1### The error may involve defaultParameterMap### The error occurred while setting parameters### SQL: INSERT INTO cms_comment(    id,    category_id,    content_id,    title,    content,    name,    ip,    create_date,    audit_user_id,    audit_date,    del_flag   ) VALUES (    ?,    ?,    ?,    ?,    ?,    ?,    ?,    ?,    ?,    ?,    ?   )### Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'title' at row 1; SQL []; Data truncation: Data too long for column 'title' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'title' at row 1org.springframework.dao.DataIntegrityViolationException: ### Error updating database.  Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'title' at row 1### The error may involve defaultParameterMap### The error occurred while setting parameters### SQL:     INSERT INTO cms_comment(id,    category_id,    content_id,    title,    content,    name,    ip,    create_date,                      audit_user_id,    audit_date,    del_flag   )     VALUES (    ?,    ?,    ?,    ?,    ?,    ?,    ?,    ?,    ?,    ?,    ?   )### Cause: com.mysql.jdbc.MysqlDataTruncation: Data truncation: Data too long for column 'title' at row 1; SQL []; Data truncation: Data too long for column 'title' at row 1; nested exception is com.mysql.jdbc.MysqlDataTruncation:                Data truncation: Data too long for column 'title' at row 1    at org.springframework.jdbc.support.SQLStateSQLExceptionTranslator.doTranslate(SQLStateSQLExceptionTranslator.java:102)    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:73)    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)    at org.mybatis.spring.MyBatisExceptionTranslator.translateExceptionIfPossible(MyBatisExceptionTranslator.java:74)    at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:399)    at com.sun.proxy.$Proxy27.insert(Unknown Source)

通过提示可以看出,执行SQL语句时报字段超长的错误,文章的中文标题在乱码之后,超出了title字段所允许的长度,因为数据库中title字段的长度为255:

 

解决办法:

打开tomcat的conf目录下的server.xml文件,在Connector标签中添加 URIEncoding="utf-8" 即可:

 

重启tomcat,再次测试,评论提交成功,也不再乱码了:

 

附jsp页面中EL表达式取值部分代码:

 

如果觉得本文对您有帮助,不妨扫描下方微信二维码打赏点,您的鼓励是我前进最大的动力:

 

转载于:https://www.cnblogs.com/jun1019/p/7018564.html

你可能感兴趣的文章
Java中的Future相关
查看>>
CGAL Catmull-Clark Subdivide Surface
查看>>
赛车入门 -- 专有技术名词
查看>>
接收IWebBrowser2的自动化事件
查看>>
需求入门: 需求工程=需求开发+需求管理
查看>>
androidmanifest.xml权限中文说明
查看>>
matlab练习程序(感知哈希对比图片)
查看>>
多媒体指令(图像灰度化)
查看>>
sqlserver数据库大型应用解决方案总结
查看>>
枚举系统设备
查看>>
C#形参,实参,值传递参数,引用传递参数,输出参数,参数数组的学习
查看>>
在Salesforce中创建Approval Process
查看>>
.NET v2.0 下的高精度计数器 —— Stopwatch [.NET v2.0, C#]
查看>>
Remoting入门实例
查看>>
MongoDB的使用
查看>>
[LeetCode] Meeting Rooms I & II
查看>>
[译]Selenium Python文档:六、页面对象
查看>>
[Windows Azure] How to Scale an Application
查看>>
RC4 in TLS is Broken: Now What?
查看>>
linux下core文件调试方法
查看>>