private static final String JAVASCRIPT_TYPE = "text/javascript";
ObjectMapper mapper = new ObjectMapper();
String jsonString = null;
try {render(JAVASCRIPT_TYPE, result, headers);
/**
* 直接输出内容的简便函数.
*
* eg. render("text/plain", "hello", "encoding:GBK");
* render("text/plain", "hello", "no-cache:false");
* render("text/plain", "hello", "encoding:GBK", "no-cache:false");
*
* @param contentType
* String 数据报
* @param content
* String 数据内容
* @param headers
* String... 可变的header数组,目前接受的值为"encoding:"或"no-cache:",默认值分别为UTF-8和true.
*/
public static void render(final String contentType, final String content, final String... headers) {
HttpServletResponse response = initResponse(contentType, headers);
PrintWriter out = null;
try {
out = response.getWriter();
out.write(content);
out.flush();
out.close();
} catch (IOException e) {
throw new RuntimeException(e.getMessage(), e);
}
}