JAX-RS带有针对乌尔都语/阿拉伯语文本的泽西返回编码字符串

时间:2018-03-08 05:46:20

标签: java rest jax-rs

我在JAVA(JAX_RX)中有一个简单的REST服务。我必须将一些乌尔都语/阿拉伯语作品返回给客户(这是我的案例的网页)。在客户端,我得到utf-8编码的字符串。我必须显示原始字符串。

下面是包含我必须返回的示例查询的类信息。 **班级**

mail.Body = template;

当我从前端Message processed successfully for Trigger helloWorld. Message processed successfully for Logger logIncoming. Message processed successfully for Assignment assignSecondaryTracking. **Error processing message in Notification sendMail.** Message processed successfully for Reply getMail. 查询时,我得到此输出@Path("/book") public class Book { @GET @Path("/query") public Response getParams( @QueryParam("url") String url, @QueryParam("text") String text) throws IOException { if ( url != null) { return Response.status(200).entity("Given URL: " + url).build(); } else if ( text != null ) { return Response.status(200).entity ( new String( "گدھا" ) ).build(); } return Response.status(200).entity("Invalid format !!!").build(); } } 。这是编码utf-8。如何获取原始文本http://localhost:8080/WSdemo/book/query?text=%DA%86%DB%8C%D8%A6%D8%B1

1 个答案:

答案 0 :(得分:0)

尝试将端点声明如下,指定所需的字符编码:

@GET
@Path("/query")
@Produces("text/plain;charset=UTF-8")
public Response getParams(..) {..}

或者我猜你可以在Response

上设置编码
return Response.status(200)
    .header("Content-Type", "text/plain;charset=UTF-8")
    .entity(text)
    .build();
相关问题