首页 \ 问答 \ Groovy编码问题(Encoding issue under Groovy)

Groovy编码问题(Encoding issue under Groovy)

我正在开发一个应该在不同语言(德语,西班牙语等)下工作的应用程序。 该应用程序使用Oracle数据库。 我有CRUD业务流程,并拥有标准视图(创建,编辑,显示,列表)。 创建,显示和列出包含特殊字符(如ä,ö,ü等)的任何记录都没有问题。但是,当编辑包含任何这些字符的任何条目时,我都会得到编码版本。 即ä 代替ä&üml; 而不是öü 而不是ü

等等。

任何提示如何解决这个问题?

谢谢!

更新感谢您的帮助。 我将描述完整的场景:

我有一个用grails编写的web应用程序(groovy on grails)。 为了开发我使用Jetty作为服务器和Oracle 10g。 对于测试和生产,我使用Tomcat 6.0.18和Oracle 10g Java版本是1.6.0_02

我有很多CRUD过程(创建,检索,更新,删除)。 该应用程序是多语言的。 也就是说,ä,ö,ü,ß,á,é,í,ó,字母(字符)必须被允许作为内容。

视图是用gsp编写的。 我正在使用标准的.gsp视图(创建,编辑,显示,列表)。 创建,显示,列表没有问题。 也就是说,如果在创建视图下输入任何使用此特殊字符的单词,则会在show.gsp或list.gsp下正确显示或列出该单词

编辑包含这些字符的记录时出现问题。 而不是-let的说 - ä出现在字段ä (这是ä的html编码)。

我有以下设置:

在Config.groovy下grails.views.gsp.encoding =“UTF-8”grails.converters.encoding =“UTF-8”

每个.gsp页面都有以下元标记:

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" pageEncoding="UTF-8"/>

每个表单都有以下属性:

<g:form accept-charset="UTF-8" method="post" >

在Tomcat下,我做了以下设置。

tomcat启动时有以下选项:

CATALINA_OPTS=-Dfile.encoding=UTF-8
JAVA_OPTS="-Duser.language=de -Duser.country=DE"

在web.xml下,我设置了以下过滤器

 <filter>
   <filter-name>SetCharacterEncoding</filter-name>
   <filter-class>filters.SetCharacterEncodingFilter</filter-class>
   <init-param>
       <param-name>encoding</param-name>
       <param-value>UTF-8</param-value>
   </init-param>
 </filter>

在myApplication / WEB-INF / classes / filters下,我复制了来自examples / WEB-INF / classes / filters的SetCharacterEncodingFilter.class

在server.xml下,我设置了以下连接器:

 <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="UTF-8" />

该方案如下所示:服务器收到编辑表单的请求。 服务器正在从数据库中检索信息,然后数据库发送已经被html编码的信息(我不这么认为),或者服务器正在对它进行编码并将其编码发送给客户端。

此外,在我的控制器,我可以看到从服务器检索到的信息不是html编码的。

我不知道为了应付这种编码问题(这花费我很多,很多时间和精力)必须完成哪个设置。

提前致谢。

路易斯


I am developing an application which should work under different languages (german, spanish, etc). The application uses an Oracle DB. I have CRUD business processes and I have the standard views (create, edit, show, list). No problems for creating, showing and listing any record containing special chars like ä,ö,ü, etc. But when I edit any entry containing any of this characters I am getting the encoded version. i.e. & auml; instead of ä & ouml; instead of ö & uuml; instead of ü

and so on.

Any hint how to solve this problem?

Thanks!

UPDATE Thanks for your help. I will describe the complete scenario:

I have a web application written in grails (groovy on grails). For developing I am using Jetty as server and Oracle 10g. For testing and production I am using Tomcat 6.0.18 and Oracle 10g Java version is 1.6.0_02

I have many CRUD processes (create, retrieve, update, delete). The application is multilanguage. That is, ä, ö, ü, ß, á, é, í, ó, ú letters (characters) must be allowed as content.

Views are written in gsp. I am using standard .gsp views (create, edit, show, list). No problem with create, show, list. That is, if under the create view I type any word using this special characters then this will be shown or listed correctly under the show.gsp or list.gsp

The problem arises when editing a record containing such characters. Instead of -let's say- ä appears in the field an & auml; (this is the html encoding of ä).

I have the following settings:

under Config.groovy grails.views.gsp.encoding="UTF-8" grails.converters.encoding="UTF-8"

Every .gsp page has the following meta tag:

 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" pageEncoding="UTF-8"/>

Every form has the following attribute:

<g:form accept-charset="UTF-8" method="post" >

Under Tomcat I did the following settings.

tomcat is started with the following options:

CATALINA_OPTS=-Dfile.encoding=UTF-8
JAVA_OPTS="-Duser.language=de -Duser.country=DE"

Under web.xml I set the following filter

 <filter>
   <filter-name>SetCharacterEncoding</filter-name>
   <filter-class>filters.SetCharacterEncodingFilter</filter-class>
   <init-param>
       <param-name>encoding</param-name>
       <param-value>UTF-8</param-value>
   </init-param>
 </filter>

Under myApplication/WEB-INF/classes/filters I copied the SetCharacterEncodingFilter.class from examples/WEB-INF/classes/filters

Under server.xml I set the following connector:

 <Connector port="8080" protocol="HTTP/1.1"
           connectionTimeout="20000"
           redirectPort="8443" URIEncoding="UTF-8" useBodyEncodingForURI="UTF-8" />

The scenario is as follows: The server receives a request for editing a form. The server is retrieving the info from the DB and then either the DB is sending the information already html encoded (I don't think so) or the server is encoding it and sending it encoded to the client.

Moreover, at my controller I can see that the retrieved information from the server is not html encoded.

I don't know which setting has to be done in order to cope this encoding problem (which is taking me a lot, a lot of time and effort).

Thanks a lot in advance.

Luis


原文:https://stackoverflow.com/questions/1406168
更新时间:2022-10-20 08:10

最满意答案

将sectionList字段的数据类型更改为:

private Map<String, String> sectionList ;

Using Eclipse Moxy solved the issue. My requirement was to have the HashMap keys as XML nodes. Using @XmlVariableNode instead of List did the whole thing

相关问答

更多

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)