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
最满意答案
将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
相关问答
更多-
Ember.js其他适配器:映射JSON与无根(.NET Web API)(Ember.js Rest Adapter: mapping JSON with no root (.NET Web API))[2023-06-08]
Ember在这个意义上非常灵活,可以扩展适配器和序列化器,以便将应用程序与任何后端API集成。 您应该获得WebAPIAdapter,它是Web API的Ember.js模板的一部分。 另外,你可能想看看我写的这个项目,作为一个例子,基于同样的模板(我做了一些修改)。 它仍在开发中,并没有包含所有最佳实践(但),但我认为这是一个有效的例子。 你还应该看看这个回购/库 (你也可以通过NuGet安装它),它允许你预先编译你的Handlebars模板到Ember.TEMPLATES集合中。 Ember is ve ... -
listview中的Android listview适配器(json children)(Android listview adapter in listview (json children))[2021-11-03]
为什么不使用BaseAdapter,你可以在那里统治与它的外观和使用方式有关的所有内容? 只需实现getCount,getItem和getView。 有关listView的更多信息,请观看“ listView世界 ”讲座。 why not using BaseAdapter , where you rule everything related to how it looks and how it uses the data? just implement getCount,getItem, and get ... -
将RecyclerView适配器类中的JSON数组传递给Activity类(Pass JSON Array in RecyclerView Adapter Class to Activity Class)[2022-06-11]
当你必须阅读使用时,将json对象传递为String : - JJSONObject obj = new JSONObject(Stringhere); JSONArray jsonArray = obj.getJSONArray("results"); ArrayList < objectClass > somearray= new ArrayList < objectClass > (); for (int i = 0; i < jsonArray.length(); i++) { Movie o ... -
将sectionList字段的数据类型更改为: private Map
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 -
在适配器过程中访问json文档键(IBM worklight)(Accessing json document keys in adapter procedure (IBM worklight))[2023-02-14]
尝试使用JSON.parse将字符串转换为JavaScript对象。 function addGegegr(document) { var doc = JSON.parse(document); //... use doc as a regular JavaScript object } 如果JSON.parse在那里不可用,您可以通过在适配器实现文件中包含此代码来添加它。 Try using JSON.parse to turn the string into a JavaScript obje ... -
事实证明,我需要调整应用程序适配器中的handleResponse挂钩,以将新的requestData参数传递给super方法。 handleResponse (status, headers, payload, requestData) { return this._super(status, headers, payload, requestData); }, 然后我只是改变了我的问题代码的第一行 handleResponse: function(status, headers, payloa ...
-
Active Model Serializer无法使用json_api适配器(Active Model Serializer not working with json_api adapter)[2023-06-30]
关系仅根据json-api exmaples返回id和type 。 如果您需要返回有关此关系的更多信息,则应在渲染操作中添加include选项。 防爆。 PostController.rb class PostsController < ApplicationController def show render json: @post, include: 'comments' end end 串行器 class PostSerializer < ActiveModel::Serialize ... -
简而言之,你基本上想要做的就是在Zends服务管理器中注册服务(工厂),这样你就可以从你的应用程序的许多类和模块中访问它们。 它们就像预先包装好的物品,可以在需要时随时使用! 重点是他们已经拥有了他们已经注入的所有东西。 现在,您可以通过各种方式在服务管理器中注册服务,例如从module.config.php或Module.php中注册服务,则选择是您的。 重要的是要记住的是,你只是想能够要求一些东西,而不用担心所有的基础细节。 默认的Db适配器:如果您在主应用程序配置(global.php和local.p ...
-
我认为,递归是处理list(add(fromJson(it))正确方式list(add(fromJson(it)) ,主要问题是在结构中,结构本身是递归的,正确的方法是将结构和引用平铺到另一个对象类型。 关于第二,这也是结构不好的问题。 您可以通过继承来解决这个问题。 然后检查目标类型本身。 interface X { } data class A : X { } data class B : X { } @FromJson fun fromJson(json: C): X { } I think, r ...
-
这确实是MobileFirst Platform Foundation 7.1的缺陷和回归。 开发团队将致力于解决这个问题。 要跟踪此问题,已打开以下APAR:PI74759:不能通过JSON对象或JSON阵列作为MFP.SERVER.INVOKEPROCEDURE的参数 更新:安装最新的8.0 iFix以获取此问题的修复程序,该修复程序驻留在服务器上,因此需要安装新的服务器。 This is indeed a defect and a regression from MobileFirst Platfor ...