Servlets jersey不支持treturn gzip字节

Servlets jersey不支持treturn gzip字节,servlets,gzip,jersey,Servlets,Gzip,Jersey,现在我使用response返回一个xml文件。但当文件较大时,性能似乎不好。 所以我想知道如何返回字节[](gzip/xml) IE/firefox还可以从gzip字节数组中显示此xml文件 在使用servlet之前,它可以自动显示xml文件 @GET @Path("/Test/{CustomerId}") @Produces("application/xml") public Response getTest() throws IOException { return Response

现在我使用response返回一个xml文件。但当文件较大时,性能似乎不好。 所以我想知道如何返回字节[](gzip/xml) IE/firefox还可以从gzip字节数组中显示此xml文件

在使用servlet之前,它可以自动显示xml文件

@GET
@Path("/Test/{CustomerId}")
@Produces("application/xml")
public Response getTest() throws IOException {
    return Response.ok().entity(new FileInputStream("CC100_PC.xml")).build();

}

顺便问一下,如何支持init和Destroy函数,我想在init函数中添加一些数据库连接并销毁它

只需将GZIPContentEncodingFilter添加到Jersey应用程序中即可-请参阅

如果客户端支持GZIP,它将使用GZIP自动压缩它(从Accept Encoding HTTP头中可以看出)