How to set the charset with JAX-RS?

后端 未结 7 1100
时光说笑
时光说笑 2020-12-08 09:30

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 th

7条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-08 10:04

    What I do is to get an instance of the servlet response object:

    protected @Context HttpServletResponse response;
    

    And then set the character encoding to utf-8:

    response.setCharacterEncoding("utf-8");
    

    That works for me.

提交回复
热议问题