RESTEasy/jax-rs进行字符编码响应 [英] character encoding responses with RESTEasy / jax-rs

查看:125
本文介绍了RESTEasy/jax-rs进行字符编码响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在服务器上为jax-rs使用RESTeasy进行设置.我的客户端发送了一个包含字符✓"的字符串,服务器可以存储该字符(我可以确认它已正确存储在服务器上).但是,服务器似乎无法在响应中返回✓",而是返回?"被发送.

I'm set up using RESTeasy for jax-rs on my server. My client sends a string containing the character '✓', and the server can store that character (I can confirm that it is being stored correctly on the server). However, the server can't seem to return the '✓' in a response - instead, a '?' gets sent.

我假设我需要指定一个返回编码或其他内容,但是我不知道在哪里执行该操作,或者不知道如何检查当前编码是什么!

I'm assuming I need to specify a return encoding or something, but I don't know where to do this, or how to check to see what the current encoding is!

如何在服务器上指定编码,以便在响应中返回✓"?

How do I specify the encoding on my server so that I can return a '✓' in a response?

编辑以添加代码

我的服务器代码:

@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)

响应正文:

?

推荐答案

有点漫长而漫长,所以我将其放入答案中,但这主要是评论.

A bit rambling and long so I put it into an answer, but it is mostly a comment.

出于好奇,您正在使用什么版本的Java,Rest Easy,编译器设置?

Out of curiosity, what versions of Java, Rest Easy, compiler settings are you using?

我使用了您在MacOS 10.6,RestEasy 2.2.3.GA,Java 1.6.0_29,Tomcat 7.0.22上发布的代码,并且这些代码正常工作(我删除了参数部分,但似乎不相关)

I used your code you posted here on MacOS 10.6, RestEasy 2.2.3.GA, Java 1.6.0_29, Tomcat 7.0.22, and it worked correctly (I removed the param piece, but it doesn't seem relevant).

在服务器端用于读取和写入的代码是什么?阅读有编码问题吗?

What is the code used to read and write on the server side? Are there encoding issues reading?

我也怀疑您的响应标题,尤其是:

I'm also suspicious of your response headers, particularly:

Content-Type    text/html;charset="UTF-8"

我认为应该是:

Content-Type    text/html;charset=UTF-8

这篇关于RESTEasy/jax-rs进行字符编码响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆