English 中文(简体)
GZIP JSON AJAX response text is empty
原标题:

I am facing a problem, while encoding the response that I send back for an AJAX request, using GZIP. Can anyone give me some pointers on this please?

  1. There is an AJAX request from the JSP,
  2. An action class (Struts) at the server side handles the request,
  3. The response is prepared as a JSON object,
  4. The JSON string is written to the Response object and sent back,
  5. the JSON string is read from the responseText property of the xmlHttp object back at the jsp

This works fine. However, instead of sending the raw JSON data, if I send back encoded JSON data, then there are issues.

Server Side Code to create GZip ed JSON :

// jsonStr = JSONObj.toString();  
ByteArrayOutputStream bos = new ByteArrayOutputStream();  
GZIPOutputStream gzip = new GZIPOutputStream(bos);  
gzip.write(jsonStr.getBytes());  
gzip.close();  
String newStr = new String(bos.toByteArray());  
// set the response header and send Encoded JSON response  
response.setHeader("Content-Type", "application/json");  
response.setHeader("Content-Encoding", "gzip");  
response.setHeader("Vary", "Accept-Encoding");  
pw = response.getWriter();  
pw.write(newStr);  
pw.close();

At the JSP :

// marker  
alert( Length of the received Response Text :   + xmlHttp.responseText.length);
// evaluate the JSON  
jsonStr = eval( (  + xmlHttp.responseText +  ) );

The alert box, on receiving the response, reports length as 0!

问题回答

暂无回答




相关问题
ajax login using httpRequest?

I am trying to develop my login script to give feedback to the user if the login is valid or not. Basically if it isn t correct a div box will show saying its wrong, if its correct it will show its ...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

How can i update div continuously

I have asp.net application where i have a div which showing the value from other site. The value of that site is changing continuously. I want that my div will automatically update in some interval ...

热门标签