下面分享一下HttpServletResponse响应数据的示例:
// 返回结果
private void sendJson(HttpServletResponse response, String result) {
try {
response.setHeader("Content-type", "text/html;charset=UTF-8");
response.setCharacterEncoding("UTF-8");
response.getWriter().print(result);
response.getWriter().close();
LOG.info("responseData=" + result);
LOG.info("---------------------------");
LOG.info(serverIdThreadLocal.get() + "处理时间:"
+ computerTime(System.currentTimeMillis() - timeThreadLocal.get()));
LOG.info("---------------------------");
} catch (Exception e) {
LOG.error(ChineseConstant.RESPONSE_HTML_ERROR, e);
}
}