EL表达式取值中文再发送请求时会乱码
问题描述:
在网站底部进行评论,点击提交按钮时,后台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: 0
2017-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 1
org.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表达式取值部分代码:

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

EL表达式取值中文再发送请求时会乱码的更多相关文章
- JSP中EL表达式取值问题记录(已解决)
***************************2015-10-28 22:21************************* 问题描述如下: 在当前的jsp页面已经有了如下代码: < ...
- 关于EL表达式取值的问题
EL表达式取值时,如果没有指定作用域,EL表达式会自动按照作用域的大小,从小到大依次去找;比如${s},会自动按照"pageContext,request,session,applicati ...
- 独立的js文件中不能使用EL表达式取值
在独立的js文件中写了一个EL表达式取值,发现没有取到值,原因在于不能在独立的js文件中使用EL表达式,可以在jsp页面定义全局变量,然后在js文件中引用
- EL 表达式 取值将 < 转成 &1t 问题
因为用JeeCMS,JeeCMS后台会存入<p></p> 内容到数据库中 用play框架取后台值的时候 用的EL表达式在前台展示 出现将< 转成 &1t HTML ...
- hibernate查询之后用el表达式取值时遇到的问题
String juniorApprovalUserHql = "select c.id,c.username from UserInfo c left join c.userRole whe ...
- Struts2中EL表达式取值
http://blog.csdn.net/cuihaiyang/article/details/41950141 (写的不错,可以知道为什么struts2可以用El取属性值的问题.正常el从reque ...
- springmvc el表达式取值顺序问题
最近遇到一个问题,两次访问同一个controler, 第二次根据判断条件,明明没有设置model的值,在jsp中通过${data}还是能取到值,最后找到原因是 我为了能够加快响应速度,在session ...
- 在jsp的js和css里面使用EL表达式取值|style里面用$取值
众所周知,如果直接在jsp的js或者css语句块里面写${***}取值的话,程序会不识别这玩意,但是,我们有时候确实需要动态取值,比如,js为了获得对象的某一个值,不方便用js的getElementB ...
- el表达式取值优先级
不同容器中存在同名值时,从作用范围小到大的顺序依次尝试取值:pageContext->request->session->application
随机推荐
- PHP 5.3版本上MS SQL Server的连接配置
折腾了好久,最后终于连接成功了! 注:我使用的的phpStudy. php.ini中配置: ;这是php中带的驱动 extension=php_sqlsrv.dll extension=php_pdo ...
- [解决问题]selenium.remote.UnreachableBrowserException 异常分析并解决问题
I have a set of automations that work fantastically in Firefox and Chrome, and I'd like to launch an ...
- 修改linux 最大文件限制数 ulimit
1)修改当前交互终端的limit值 查询当前终端的文件句柄数: ulimit -n 回车,一般的系统默认的1024. 修改文件句柄数为65535,ulimit -n 65535.此时系统的文件句柄数为 ...
- VI 基本可视模式
可视模式让你可以选择文件的一部分内容,以便作比如删除,复制等工作. 进入可视模式 v 用v命令进入可视模式.当光标移动时,就能看到有一些文本被高亮显示了,它们就是被选中的内容. 三种可视模式 v 一个 ...
- shell脚本中解决SCP命令需要输入密码的问题
使用密钥文件. 这里假设主机A(192.168.100.3)用来获到主机B(192.168.100.4)的文件. 在主机A上执行如下命令来生成配对密钥: ssh-keygen -t r ...
- linux下串口工具minicom
系统环境:ubuntu 14 .04 和ubuntu 16.04 我当时的需要主要是两个,能够看到正常串口输出,并且把串口内容实时输出到文件中 那接下来工作主要是两个:1.安装 2.配置 相信各位 ...
- git学习笔记(四)—— 分支管理
一.创建与合并分支 git branch //查看分支 git branch <name> //创建分支 git checkout <name> //切换分支 git chec ...
- mac 终端添加颜色
1.打开终端,然后找到终端偏好设置,选择自己喜欢的颜色 2.然后切换到当前用户的家目录: cd ~ 3.打开文件,开始编辑".bash_profile", 添加下面两句 expor ...
- Android一些小技巧
1:设置选中图片的背景颜色 this.gridviewToolbar = (GridView) super.findViewById(R.id.gridviewbar); this.gridviewT ...
- Linux命令-进程后台执行:nohup(就是不挂起的意思)
nohup 就是不挂起的意思( no hang up) 用途:LINUX命令用法,不挂断地运行命令. 语法: nohup Command [ Arg ... ] [ & ] 描述:nohup ...