导出文件时,发生异常!

@JFinalimage.png

评论区

任小伊roy

2020-01-16 14:11

@JFinal 大佬帮帮忙,把这个异常处理掉,实在没辙了

鼻涕刘o0

2020-01-16 14:24

不贴代码,怎么解决

任小伊roy

2020-01-16 14:42

导出成功之后抛出异常的,应该是getOutputStream()与getWriter()的问题,但是不知道怎么解决

任小伊roy

2020-01-16 14:45

@Override
public void handle(String target, HttpServletRequest request,
HttpServletResponse response, boolean[] isHandled) {
request = new XssRequestWrapper(request);
next.handle(target, request, response, isHandled);
}

任小伊roy

2020-01-16 14:46

public void write(HttpServletResponse rsp, String file) {
OutputStream out = null;
try {
String fileName = URLEncoder.encode(file, "utf-8");
rsp.reset();
rsp.setHeader("Content-disposition", "attachment; filename=" + fileName);
rsp.setContentType("application/msexcel;charset=UTF-8");
out = rsp.getOutputStream();
workBook.write(out);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
out.flush();
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

任小伊roy

2020-01-16 14:48

@鼻涕刘o0 就这几个地方,导出成功之后抛出异常

JFinal

2020-01-16 14:50

@任小伊roy 如果异出是在 controller 中进行的,在最后一行添加一句:
renderNull();

如果导出是在 handler 中进行的,注意要去掉 :
next.handle(target, request, response, isHandled);

并且要添加下面一行代码:
isHandled[0] = true;

热门反馈

扫码入社