我在我的服务器上使用 RESTeasy for jax-rs 进行设置。我的客户端发送一个包含字符“✓”的字符串,服务器可以存储该字符(我可以确认它被正确存储在服务器上)。但是,服务器似乎无法在响应中返回“✓”——而是一个“?”被发送。
我假设我需要指定一个返回编码或其他东西,但我不知道在哪里做这个,或者如何检查当前编码是什么!
如何在我的服务器上指定编码以便我可以在响应中返回“✓”?
编辑添加代码
我的服务器代码:
@Path("compiled/{rootReportGroupId}")
@GET
@Produces("text/html; charset=UTF-8")
@NoCache
public String getCompiledReports(@PathParam("rootReportGroupId") Long rootReportGroupId){
return "✓";
}
示例请求:
GET http://192.168.0.12:8888/rest/reports/compiled/190
Host 192.168.0.12:8888
User-Agent Mozilla/5.0 (Macintosh; Intel Mac OS X 10.6; rv:7.0.1) Gecko/20100101 Firefox/7.0.1
Accept text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language en-us,en;q=0.5
Accept-Encoding gzip, deflate
Accept-Charset ISO-8859-1,utf-8;q=0.7,*;q=0.7
Connection keep-alive
Content-Type application/json
响应头:
Cache-Control public, no-transform, no-cache
Content-Type text/html;charset="UTF-8"
Content-Length 1
Server Jetty(6.1.x)
响应主体:
?
最佳答案
有点漫无边际,所以我把它放到了一个答案中,但它主要是一条评论。
出于好奇,您使用的是什么版本的 Java、Rest Easy、编译器设置?
我使用了你在 MacOS 10.6、RestEasy 2.2.3.GA、Java 1.6.0_29、Tomcat 7.0.22 上发布的代码,它工作正常(我删除了参数部分,但它似乎不相关) .
服务器端读写用的代码是什么?读取是否存在编码问题?
我也怀疑你的响应头,特别是:
Content-Type text/html;charset="UTF-8"
我认为应该是:
Content-Type text/html;charset=UTF-8
关于java - 使用 RESTEasy/jax-rs 的字符编码响应,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8233874/