从控制器发送响应后,我试图立即执行一个方法(执行时间很长),而不必让客户端等待响应。
我发送响应的源代码如下,
@RequestMapping(value = "exportExcelReportService", method = RequestMethod.POST)
@ResponseStatus(value = HttpStatus.OK)
public void exportExcelReportServiceGetJsonObject(@ModelAttribute ReqParam reqParam, HttpServletResponse response) {
java.io.PrintWriter wr;
try {
wr = response.getWriter();
response.setStatus(HttpServletResponse.SC_OK);
wr.print(response);
wr.flush();
wr.close();
exportDataUsingVMService.getByteArrayForExcelSheet(reqParam);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
在这里,在将响应发送到客户端之后,将执行getByteArrayForExcelSheet。但是我无法用这种方法创建会话,
public void getByteArrayForExcelSheet(ReqParam reqParam) {
JSONObject jObject = null;
HttpSession httpsession = request.getSession(false);
}
在这样自动连接请求的地方,
@Autowired
private HttpServletRequest request;
我在getByteArrayForExcelSheet
中遇到异常,
java.lang.IllegalStateException: Cannot create a session after the response has been committed