How to set the charset with JAX-RS?

后端 未结 7 1102
时光说笑
时光说笑 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:00

    It is also possible to use ResponseBuilder.header(...) method to set the content type with the charset. See below for a code sample (using JAX-RS 1.1.1, CXF 2.3.1).

    final Response myResponse = Response.status(Response.Status.BAD_REQUEST)
        .entity("La requête n'est pas correcte.\n ...")
        .header(HttpHeaders.CONTENT_TYPE, MediaType.TEXT_PLAIN+"; charset=ISO-8859-15" )
        .build();
    

提交回复
热议问题