Tomcat 中的 Grails 请求参数编码问题 [英] Grails request parameters encoding issue in Tomcat
问题描述
我的 grails 应用无法正确解码请求参数.
My grails app will not decode request parameters correctly.
在 config.groovy 中:
In config.groovy:
grails.views.gsp.encoding = "UTF-8"
grails.converters.encoding =UTF-8"
我所有的 gsp 在页面指令以及 <meta http-equiv="Content-Type" 内容上使用
在 head 元素中.contentType="text/html; charset=UTF-8"
="text/html; charset=UTF-8"/>
All my gsp's use contentType="text/html; charset=UTF-8"
on the page directive as well as <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
in the head element.
但是,当我从控制器中的 param 对象接收到发布的参数时,应用程序只会打印垃圾...
However, when i receive the posted parameters from the param object in my controller, the app just prints garbage...
我使用的是在 Tomcat 5 上部署的 Grails 1.3.7 版本.除 tomcat 之外的其他已安装插件:
I'm using Grails 1.3.7 version deployed over Tomcat 5. Other installed plugins except tomcat:
休眠 1.3.7jQuery 1.7.1弹簧安全核心 1.2.6webxml 1.4
hibernate 1.3.7 jquery 1.7.1 spring-security-core 1.2.6 webxml 1.4
通过进一步的调试,我注意到该应用程序将在 jetty 中运行良好.因此我怀疑它一定是一个 tomcat 问题.我的问题类似于这篇文章(可惜我没有使用 Shiro 插件).
From further debugging, i've noticed that the app will run fine in jetty. Therefore i suspect it must be a tomcat issue. My issue is similar to this post (alas i'm not using the Shiro plugin).
有人可以帮忙吗?
推荐答案
您需要将 URIEncoding='UTF-8'
添加到 conf/server 中的 Connector
元素.xml,例如
You need to add URIEncoding='UTF-8'
to the Connector
elements in conf/server.xml, e.g.
<Connector port='8080' protocol='HTTP/1.1' connectionTimeout='20000'
redirectPort='8443' URIEncoding='UTF-8' />
此处描述:https://wiki.apache.org/tomcat/FAQ/CharacterEncoding
这篇关于Tomcat 中的 Grails 请求参数编码问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!