我从产生的Apache POI服务器上的Excel文件。而不是写我要下载的文件的服务器上。下面的代码是写在服务器上的文件。我想修改它,为了直接下载该文件。
try (FileOutputStream outputStream = new FileOutputStream(path+"filename.xlsx")) {
workbook.write(outputStream);
}catch (Exception e){
e.printStackTrace();
}
我想你想要做的是这样的
public class A extends HttpServlet {
@Override
protected void service(HttpServletRequest rq, HttpServletResponse rs) {
// ...
try {
rs.setContentType("application/vnd.ms-excel");
workbook.write(rs.getOutputStream());
} catch (IOException e) {
e.printStackTrace();
}
// ...
}
}