getWriter() has already been called for this response 的解决办法

2019-07-03 11:08:49 浏览数 (1)

注释部份为有问题的写法。

代码语言:javascript复制
try {
    //有问题的部份
	//PrintWriter out = null;
	//out = response.getWriter();
	// String json = new ObjectMapper().writeValueAsString(map);
	//out.write(json);
	//out.flush();
	//out.close();

	outputStream = response.getOutputStream();
	String json = new ObjectMapper().writeValueAsString(map);
	outputStream.write(json.getBytes());
	outputStream.flush();
	outputStream.close();
} catch (IOException e) {
	LOGGER.error(e.getMessage(), e);
} finally {
	if (outputStream != null) {
		try {
			outputStream.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}

0 人点赞