json responseJson

private void doResoponseJson(HttpServletResponse resp,String jsonString){

Trace.logError(Trace.COMPONENT_ACTION,"返回结果:"+jsonString); OutputStream eos =null; InputStream eTargetIS=null; try{ resp.setContentType("text/json"); resp.setCharacterEncoding("UTF-8"); resp.setHeader("Cache-Control", "no-cache"); resp.setHeader("Pragma", "no-cache"); resp.setHeader("Expires", "date"); eos = resp.getOutputStream(); eTargetIS = new ByteArrayInputStream(jsonString.getBytes("UTF-8")); int r; while ((r = eTargetIS.read()) != -1) { eos.write(r); } eTargetIS.close(); eos.flush(); eos.close(); } catch (Exception e1) { Trace.logError(Trace.COMPONENT_ACTION,"Ajax返回信息时出现异常:",e1); } finally{ try{ if(eos!=null){ eos.close(); } } catch(Exception e){ Trace.logError(Trace.COMPONENT_ACTION,"Ajax返回信息后关闭OutputStream出现异常:",e); } try{ if(eTargetIS!=null){ eTargetIS.close(); } } catch(Exception e){ Trace.logError(Trace.COMPONENT_ACTION,"Ajax返回信息后关闭InputStream出现异常:",e); } }

  

}

上一篇:C# 日志系统 log4net 配置及使用


下一篇:浅谈android4.0开发之GridLayout布局