如何用JAX-RS设置字符集? [英] How to set the charset with JAX-RS?
问题描述
如何使用JAX-RS设置字符集?我尝试过 @Produces(text / html; charset = UTF-8)
但是被忽略,只有 text / html
与HTTP头一起发送。我想在MessageBodyWriter中设置字符集,但不想通过自己的反射分析@Produces注释来提取媒体类型。
How can I set the charset with JAX-RS? I've tried @Produces("text/html; charset=UTF-8")
but that was ignored and only text/html
was send with the HTTP header. I want to set the charset within a MessageBodyWriter, but don't want to extract the media type by analysing the @Produces annotation via reflection by myself.
推荐答案
As Daemon在评论中指出,最新版本的JAX-RS(包括截至2012年9月的稳定版本)现在 @Produces 语法。因此,您只需使用:
As Daemon pointed out in a comment, the latest versions of JAX-RS (including the stable version as of September 2012) now do support the @Produces
syntax. So you can just use:
@Produces("text/html; charset=UTF-8")
这篇关于如何用JAX-RS设置字符集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!