如何在RESTeasy中将编码设置为UTF-8?
我在RESTeasy中编码字符串时遇到问题.问题是中文字母或任何其他非拉丁字符无法正确显示.如果我尝试将它们打印出来(或作为响应发送),我会收到"??????"反而. 我相信RESTeasy中的默认编码是us-ascii.您知道如何将其更改为UTF-8吗?也许对此问题还有另一种解决方案?
I have a problem with encoding strings in RESTeasy. The problem is that chinese alphabet or any other non-latin characters are not displayed properly. If I try to print them out (or send as response) I get "?????" instead. I believe that default encoding in RESTeasy is us-ascii. Do you know how to change it to UTF-8? Maybe there is another solution to this problem?
这里是我的代码的一小段内容:
Here is a short passage from my code:
@POST
@Path("post")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public String uploadData(@MultipartForm DataUploadForm uploadForm) {
...
//the code below is just for the purpose of presentation
String text = "some non-latin alphabet signs here"
System.out.println(text); // "??????" is printed out
return text; //"??????" is returned
}
我的resteasy-jaxrs-3.0-beta-2在Tomcat 7.0上运行.
My resteasy-jaxrs-3.0-beta-2 is running on Tomcat 7.0.
谢谢!
这与resteasy或jax-rs mate无关.
This is not about resteasy or jax-rs mate.
检查这篇文章
您可能需要研究几件事:
There are several things you may want to look into:
- 如果数据来自数据库,则需要确保数据库中的数据已正确编码.
- 您的JVM环境正在使用utf8进行编码
- 这可能是IDE的问题,因为IDE和您的tomcat可能运行在不同的位置 配置.
- If the data is from DB, then you need to make sure data in DB it is encoded correctly.
- Your JVM environment is encoding using utf8
- It could be an issue of IDE, because IDE and your tomcat might running on different configurations.