我有一个 Tapestry 应用程序,它从表单中检索数据,将其写入数据库,然后显示结果。只要不使用特殊字符(如 Ä、Ö、Ü、ß、€ ...),一切都运行良好。
例如,文本:
我猜这个问题与字符编码设置有关。 Tapestry Java 类:
我会翻译中文。以下是内容翻译:
但是两者都没有成功(我寻找的是一般性解决方案而不是解决方法)。
有趣的是,this proposal 对于一些特殊字符(如ä、ö、ü、ß等)有效,但我不想使用ISO-8859-1。如何设置Tapestry在表单中使用的编码为UTF-8?我错过了什么或者我的问题完全不同的原因? 编辑:我进行了一项没有数据库的测试,问题仍然存在,所以这不是关于数据库端错误编码设置的问题。
例如,文本:
TestäöüßÄÖÜ€$
会产生
TestäöüÃÃÃÃâ¬$
我猜这个问题与字符编码设置有关。 Tapestry Java 类:
@Component(parameters = {"clientValidation=false"})
private Form form;
@Component(parameters = {"value=someDTO.name"})
private TextField someNameField;
Tapestry 模板:
<t:form t:id="form">
...
<t:textfield t:id="someNameField"/>
...
</t:form>
我会翻译中文。以下是内容翻译:
我在多个地方检查了我的编码设置:
- HTML源代码:
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
Tapestry settings (this should be the default anyway):
tapestry.charset=UTF-8
Firefox says (Tools>Page Info: Encoding): UTF-8.
The underlying database (Oracle) also uses UTF-8:
character_set_system utf8
然后我检查了POST请求的头部,注意到两件事:
There is no content type specified in the header. I would expect something like this:
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
Spaces are encoded with + instead of %20.
我也尝试了以下内容:
@Component(parameters = {"clientValidation=false", "enctype='application/x-www-form-urlencoded; charset=UTF-8'"})
private Form form;
并且
@Component(parameters = {"clientValidation=false", "enctype='application/x-www-form-urlencoded; charset=UTF-8'", "accept-charset='utf-8'"})
private Form form;
但是两者都没有成功(我寻找的是一般性解决方案而不是解决方法)。
有趣的是,this proposal 对于一些特殊字符(如ä、ö、ü、ß等)有效,但我不想使用ISO-8859-1。如何设置Tapestry在表单中使用的编码为UTF-8?我错过了什么或者我的问题完全不同的原因? 编辑:我进行了一项没有数据库的测试,问题仍然存在,所以这不是关于数据库端错误编码设置的问题。