Ho problemi using Gzip compression and JQuery together. Sembra che possa essere causato dal modo in cui sto inviando risposte JSON nelle mie azioni Struts. Io uso il prossimo codice per inviare i miei oggetti JSON indietro.Come inviare JSON indietro con JAVA?
public ActionForward get(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
JSONObject json = // Do some logic here
RequestUtils.populateWithJSON(response, json);
return null;
}
public static void populateWithJSON(HttpServletResponse response,JSONObject json) {
if(json!=null) {
response.setContentType("text/x-json;charset=UTF-8");
response.setHeader("Cache-Control", "no-cache");
try {
response.getWriter().write(json.toString());
} catch (IOException e) {
throw new ApplicationException("IOException in populateWithJSON", e);
}
}
}
C'è un modo migliore di inviare JSON in un'applicazione Web Java?
Ho usato response.setContentType ("application/json; charset = UTF-8"); invece di response.setContentType ("text/x-json; charset = UTF-8"); – bentzy