我的一段代码是
@POST
@Path("/getJSONCompareData")
@Produces(MediaType.APPLICATION_JSON)
public Object getJSONCompareData(@FormParam("testRunNum") String TRun,@FormParam("rptName") String reportName) {
if(debugLevel>2)
Log.debugLog(className, "getJSONStatsData", "", "", "Methad called");
Object obj=null;
try {
int testRunNum = Integer.parseInt(TRun);
String rptName = reportName;
JSONParser parser=new JSONParser();
String statsReportNameDir = Config.getWorkPath() + "/webapps/logs/TR" + testRunNum + "/reports/compareReports/" + rptName + "/compare.report";
obj=parser.parse(new FileReader(statsReportNameDir));
}catch(Exception e){
e.printStackTrace();
Log.stackTraceLog(className, "getJSONStatsData", "", "", "Exception - ", e);
}
return obj;
}
我正在阅读的文件大小约为 10MB
我想压缩数据,因为它通过网络需要 1 分钟
我如何压缩我的 Obj 并在 ajax 调用中处理
最佳答案
您可以使用服务器上的 GZIP 配置压缩 JSON 响应。
现代浏览器也支持gzip 压缩内容像Apache、Tomcat、JBoss 等服务器也支持gzip 压缩。
因此,如果在服务器中启用了gzip,它会压缩数据然后发送给客户端。
可以引用文章http://viralpatel.net/blogs/enable-gzip-compression-in-tomcat/
GZIP 压缩不仅可以提高 js、jsp 文件的性能,还可以提高 http 请求的性能,因为数据将被压缩
关于javascript - 如何在java中发送响应期间压缩Rest服务中的数据(对象),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38691202/